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 * The full GNU General Public License is included in this distribution in the
10 * file called LICENSE.
12 * Contact Information:
13 * wlanfae <wlanfae@realtek.com>
14 ******************************************************************************/
16 #include <linux/etherdevice.h>
17 #include "rtl819x_TS.h"
19 static void TsSetupTimeOut(struct timer_list *unused)
23 static void TsInactTimeout(struct timer_list *unused)
27 static void RxPktPendingTimeout(struct timer_list *t)
29 struct rx_ts_record *pRxTs = from_timer(pRxTs, t,
31 struct rtllib_device *ieee = container_of(pRxTs, struct rtllib_device,
32 RxTsRecord[pRxTs->num]);
34 struct rx_reorder_entry *pReorderEntry = NULL;
36 unsigned long flags = 0;
38 bool bPktInBuf = false;
40 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
41 if (pRxTs->RxTimeoutIndicateSeq != 0xffff) {
42 while (!list_empty(&pRxTs->RxPendingPktList)) {
43 pReorderEntry = (struct rx_reorder_entry *)
44 list_entry(pRxTs->RxPendingPktList.prev,
45 struct rx_reorder_entry, List);
47 pRxTs->RxIndicateSeq = pReorderEntry->SeqNum;
49 if (SN_LESS(pReorderEntry->SeqNum,
50 pRxTs->RxIndicateSeq) ||
51 SN_EQUAL(pReorderEntry->SeqNum,
52 pRxTs->RxIndicateSeq)) {
53 list_del_init(&pReorderEntry->List);
55 if (SN_EQUAL(pReorderEntry->SeqNum,
56 pRxTs->RxIndicateSeq))
57 pRxTs->RxIndicateSeq =
58 (pRxTs->RxIndicateSeq + 1) % 4096;
61 "%s(): Indicate SeqNum: %d\n",
62 __func__, pReorderEntry->SeqNum);
63 ieee->stats_IndicateArray[index] =
67 list_add_tail(&pReorderEntry->List,
68 &ieee->RxReorder_Unused_List);
77 pRxTs->RxTimeoutIndicateSeq = 0xffff;
79 if (index > REORDER_WIN_SIZE) {
80 netdev_warn(ieee->dev,
81 "%s(): 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_to_jiffies(ieee->pHTInfo->RxReorderPendingTime)
97 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
100 static void TsAddBaProcess(struct timer_list *t)
102 struct tx_ts_record *pTxTs = from_timer(pTxTs, t, TsAddBaTimer);
104 struct rtllib_device *ieee = container_of(pTxTs, struct rtllib_device,
107 TsInitAddBA(ieee, pTxTs, BA_POLICY_IMMEDIATE, false);
108 netdev_dbg(ieee->dev, "%s(): ADDBA Req is started\n", __func__);
111 static void ResetTsCommonInfo(struct ts_common_info *pTsCommonInfo)
113 eth_zero_addr(pTsCommonInfo->Addr);
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 netdev_vdbg(ieee->dev, "%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 timer_setup(&pTxTS->TsCommonInfo.SetupTimer, TsSetupTimeOut,
157 timer_setup(&pTxTS->TsCommonInfo.InactTimer, TsInactTimeout,
160 timer_setup(&pTxTS->TsAddBaTimer, TsAddBaProcess, 0);
162 timer_setup(&pTxTS->TxPendingBARecord.Timer, BaSetupTimeOut,
164 timer_setup(&pTxTS->TxAdmittedBARecord.Timer,
165 TxBaInactTimeout, 0);
167 ResetTxTsEntry(pTxTS);
168 list_add_tail(&pTxTS->TsCommonInfo.List,
169 &ieee->Tx_TS_Unused_List);
173 INIT_LIST_HEAD(&ieee->Rx_TS_Admit_List);
174 INIT_LIST_HEAD(&ieee->Rx_TS_Pending_List);
175 INIT_LIST_HEAD(&ieee->Rx_TS_Unused_List);
176 for (count = 0; count < TOTAL_TS_NUM; count++) {
178 INIT_LIST_HEAD(&pRxTS->RxPendingPktList);
180 timer_setup(&pRxTS->TsCommonInfo.SetupTimer, TsSetupTimeOut,
183 timer_setup(&pRxTS->TsCommonInfo.InactTimer, TsInactTimeout,
186 timer_setup(&pRxTS->RxAdmittedBARecord.Timer,
187 RxBaInactTimeout, 0);
189 timer_setup(&pRxTS->RxPktPendingTimer, RxPktPendingTimeout, 0);
191 ResetRxTsEntry(pRxTS);
192 list_add_tail(&pRxTS->TsCommonInfo.List,
193 &ieee->Rx_TS_Unused_List);
196 INIT_LIST_HEAD(&ieee->RxReorder_Unused_List);
197 for (count = 0; count < REORDER_ENTRY_NUM; count++) {
198 list_add_tail(&pRxReorderEntry->List,
199 &ieee->RxReorder_Unused_List);
200 if (count == (REORDER_ENTRY_NUM-1))
202 pRxReorderEntry = &ieee->RxReorderEntry[count+1];
207 static void AdmitTS(struct rtllib_device *ieee,
208 struct ts_common_info *pTsCommonInfo, u32 InactTime)
210 del_timer_sync(&pTsCommonInfo->SetupTimer);
211 del_timer_sync(&pTsCommonInfo->InactTimer);
214 mod_timer(&pTsCommonInfo->InactTimer, jiffies +
215 msecs_to_jiffies(InactTime));
218 static struct ts_common_info *SearchAdmitTRStream(struct rtllib_device *ieee,
220 enum tr_select TxRxSelect)
223 bool search_dir[4] = {0};
224 struct list_head *psearch_list;
225 struct ts_common_info *pRet = NULL;
227 if (ieee->iw_mode == IW_MODE_MASTER) {
228 if (TxRxSelect == TX_DIR) {
229 search_dir[DIR_DOWN] = true;
230 search_dir[DIR_BI_DIR] = true;
232 search_dir[DIR_UP] = true;
233 search_dir[DIR_BI_DIR] = true;
235 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
236 if (TxRxSelect == TX_DIR)
237 search_dir[DIR_UP] = true;
239 search_dir[DIR_DOWN] = true;
241 if (TxRxSelect == TX_DIR) {
242 search_dir[DIR_UP] = true;
243 search_dir[DIR_BI_DIR] = true;
244 search_dir[DIR_DIRECT] = true;
246 search_dir[DIR_DOWN] = true;
247 search_dir[DIR_BI_DIR] = true;
248 search_dir[DIR_DIRECT] = true;
252 if (TxRxSelect == TX_DIR)
253 psearch_list = &ieee->Tx_TS_Admit_List;
255 psearch_list = &ieee->Rx_TS_Admit_List;
257 for (dir = 0; dir <= DIR_BI_DIR; dir++) {
258 if (!search_dir[dir])
260 list_for_each_entry(pRet, psearch_list, List) {
261 if (memcmp(pRet->Addr, Addr, 6) == 0 &&
262 pRet->TSpec.f.TSInfo.field.ucTSID == TID &&
263 pRet->TSpec.f.TSInfo.field.ucDirection == dir)
267 if (&pRet->List != psearch_list)
271 if (pRet && &pRet->List != psearch_list)
276 static void MakeTSEntry(struct ts_common_info *pTsCommonInfo, u8 *Addr,
277 union tspec_body *pTSPEC, union qos_tclas *pTCLAS,
278 u8 TCLAS_Num, u8 TCLAS_Proc)
282 if (pTsCommonInfo == NULL)
285 memcpy(pTsCommonInfo->Addr, Addr, 6);
288 memcpy((u8 *)(&(pTsCommonInfo->TSpec)), (u8 *)pTSPEC,
289 sizeof(union tspec_body));
291 for (count = 0; count < TCLAS_Num; count++)
292 memcpy((u8 *)(&(pTsCommonInfo->TClass[count])),
293 (u8 *)pTCLAS, sizeof(union qos_tclas));
295 pTsCommonInfo->TClasProc = TCLAS_Proc;
296 pTsCommonInfo->TClasNum = TCLAS_Num;
299 bool GetTs(struct rtllib_device *ieee, struct ts_common_info **ppTS,
300 u8 *Addr, u8 TID, enum tr_select TxRxSelect, bool bAddNewTs)
303 union tspec_body TSpec;
304 union qos_tsinfo *pTSInfo = &TSpec.f.TSInfo;
305 struct list_head *pUnusedList;
306 struct list_head *pAddmitList;
307 enum direction_value Dir;
309 if (is_multicast_ether_addr(Addr)) {
310 netdev_warn(ieee->dev, "Get TS for Broadcast or Multicast\n");
313 if (ieee->current_network.qos_data.supported == 0) {
334 netdev_warn(ieee->dev, "%s(): TID(%d) is not valid\n",
340 *ppTS = SearchAdmitTRStream(ieee, Addr, UP, TxRxSelect);
345 netdev_dbg(ieee->dev, "add new TS failed(tid:%d)\n", UP);
349 pUnusedList = (TxRxSelect == TX_DIR) ?
350 (&ieee->Tx_TS_Unused_List) :
351 (&ieee->Rx_TS_Unused_List);
353 pAddmitList = (TxRxSelect == TX_DIR) ?
354 (&ieee->Tx_TS_Admit_List) :
355 (&ieee->Rx_TS_Admit_List);
357 Dir = (ieee->iw_mode == IW_MODE_MASTER) ?
358 ((TxRxSelect == TX_DIR) ? DIR_DOWN : DIR_UP) :
359 ((TxRxSelect == TX_DIR) ? DIR_UP : DIR_DOWN);
361 if (!list_empty(pUnusedList)) {
362 (*ppTS) = list_entry(pUnusedList->next,
363 struct ts_common_info, List);
364 list_del_init(&(*ppTS)->List);
365 if (TxRxSelect == TX_DIR) {
366 struct tx_ts_record *tmp =
372 struct rx_ts_record *tmp =
379 netdev_dbg(ieee->dev,
380 "to init current TS, UP:%d, Dir:%d, addr: %pM ppTs=%p\n",
381 UP, Dir, Addr, *ppTS);
382 pTSInfo->field.ucTrafficType = 0;
383 pTSInfo->field.ucTSID = UP;
384 pTSInfo->field.ucDirection = Dir;
385 pTSInfo->field.ucAccessPolicy = 1;
386 pTSInfo->field.ucAggregation = 0;
387 pTSInfo->field.ucPSB = 0;
388 pTSInfo->field.ucUP = UP;
389 pTSInfo->field.ucTSInfoAckPolicy = 0;
390 pTSInfo->field.ucSchedule = 0;
392 MakeTSEntry(*ppTS, Addr, &TSpec, NULL, 0, 0);
393 AdmitTS(ieee, *ppTS, 0);
394 list_add_tail(&((*ppTS)->List), pAddmitList);
399 netdev_warn(ieee->dev,
400 "There is not enough dir=%d(0=up down=1) TS record to be used!",
405 static void RemoveTsEntry(struct rtllib_device *ieee,
406 struct ts_common_info *pTs, enum tr_select TxRxSelect)
408 del_timer_sync(&pTs->SetupTimer);
409 del_timer_sync(&pTs->InactTimer);
410 TsInitDelBA(ieee, pTs, TxRxSelect);
412 if (TxRxSelect == RX_DIR) {
413 struct rx_reorder_entry *pRxReorderEntry;
414 struct rx_ts_record *pRxTS = (struct rx_ts_record *)pTs;
416 if (timer_pending(&pRxTS->RxPktPendingTimer))
417 del_timer_sync(&pRxTS->RxPktPendingTimer);
419 while (!list_empty(&pRxTS->RxPendingPktList)) {
420 pRxReorderEntry = (struct rx_reorder_entry *)
421 list_entry(pRxTS->RxPendingPktList.prev,
422 struct rx_reorder_entry, List);
423 netdev_dbg(ieee->dev, "%s(): Delete SeqNum %d!\n",
424 __func__, pRxReorderEntry->SeqNum);
425 list_del_init(&pRxReorderEntry->List);
428 struct rtllib_rxb *prxb = pRxReorderEntry->prxb;
432 for (i = 0; i < prxb->nr_subframes; i++)
433 dev_kfree_skb(prxb->subframes[i]);
437 list_add_tail(&pRxReorderEntry->List,
438 &ieee->RxReorder_Unused_List);
441 struct tx_ts_record *pTxTS = (struct tx_ts_record *)pTs;
443 del_timer_sync(&pTxTS->TsAddBaTimer);
447 void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr)
449 struct ts_common_info *pTS, *pTmpTS;
451 netdev_info(ieee->dev, "===========>RemovePeerTS, %pM\n", Addr);
453 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List) {
454 if (memcmp(pTS->Addr, Addr, 6) == 0) {
455 RemoveTsEntry(ieee, pTS, TX_DIR);
456 list_del_init(&pTS->List);
457 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
461 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List) {
462 if (memcmp(pTS->Addr, Addr, 6) == 0) {
463 netdev_info(ieee->dev,
464 "====>remove Tx_TS_admin_list\n");
465 RemoveTsEntry(ieee, pTS, TX_DIR);
466 list_del_init(&pTS->List);
467 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
471 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List) {
472 if (memcmp(pTS->Addr, Addr, 6) == 0) {
473 RemoveTsEntry(ieee, pTS, RX_DIR);
474 list_del_init(&pTS->List);
475 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
479 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List) {
480 if (memcmp(pTS->Addr, Addr, 6) == 0) {
481 RemoveTsEntry(ieee, pTS, RX_DIR);
482 list_del_init(&pTS->List);
483 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
487 EXPORT_SYMBOL(RemovePeerTS);
489 void RemoveAllTS(struct rtllib_device *ieee)
491 struct ts_common_info *pTS, *pTmpTS;
493 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List) {
494 RemoveTsEntry(ieee, pTS, TX_DIR);
495 list_del_init(&pTS->List);
496 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
499 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List) {
500 RemoveTsEntry(ieee, pTS, TX_DIR);
501 list_del_init(&pTS->List);
502 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
505 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List) {
506 RemoveTsEntry(ieee, pTS, RX_DIR);
507 list_del_init(&pTS->List);
508 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
511 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List) {
512 RemoveTsEntry(ieee, pTS, RX_DIR);
513 list_del_init(&pTS->List);
514 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
518 void TsStartAddBaProcess(struct rtllib_device *ieee, struct tx_ts_record *pTxTS)
520 if (pTxTS->bAddBaReqInProgress == false) {
521 pTxTS->bAddBaReqInProgress = true;
523 if (pTxTS->bAddBaReqDelayed) {
524 netdev_dbg(ieee->dev, "Start ADDBA after 60 sec!!\n");
525 mod_timer(&pTxTS->TsAddBaTimer, jiffies +
526 msecs_to_jiffies(TS_ADDBA_DELAY));
528 netdev_dbg(ieee->dev, "Immediately Start ADDBA\n");
529 mod_timer(&pTxTS->TsAddBaTimer, jiffies+10);
532 netdev_dbg(ieee->dev, "BA timer is already added\n");