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(unsigned long data)
23 static void TsInactTimeout(unsigned long data)
27 static void RxPktPendingTimeout(unsigned long data)
29 struct rx_ts_record *pRxTs = (struct rx_ts_record *)data;
30 struct rtllib_device *ieee = container_of(pRxTs, struct rtllib_device,
31 RxTsRecord[pRxTs->num]);
33 struct rx_reorder_entry *pReorderEntry = NULL;
35 unsigned long flags = 0;
37 bool bPktInBuf = false;
39 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
40 if (pRxTs->RxTimeoutIndicateSeq != 0xffff) {
41 while (!list_empty(&pRxTs->RxPendingPktList)) {
42 pReorderEntry = (struct rx_reorder_entry *)
43 list_entry(pRxTs->RxPendingPktList.prev,
44 struct rx_reorder_entry, List);
46 pRxTs->RxIndicateSeq = pReorderEntry->SeqNum;
48 if (SN_LESS(pReorderEntry->SeqNum,
49 pRxTs->RxIndicateSeq) ||
50 SN_EQUAL(pReorderEntry->SeqNum,
51 pRxTs->RxIndicateSeq)) {
52 list_del_init(&pReorderEntry->List);
54 if (SN_EQUAL(pReorderEntry->SeqNum,
55 pRxTs->RxIndicateSeq))
56 pRxTs->RxIndicateSeq =
57 (pRxTs->RxIndicateSeq + 1) % 4096;
60 "%s(): Indicate SeqNum: %d\n",
61 __func__, pReorderEntry->SeqNum);
62 ieee->stats_IndicateArray[index] =
66 list_add_tail(&pReorderEntry->List,
67 &ieee->RxReorder_Unused_List);
76 pRxTs->RxTimeoutIndicateSeq = 0xffff;
78 if (index > REORDER_WIN_SIZE) {
79 netdev_warn(ieee->dev,
80 "%s(): Rx Reorder struct buffer full\n",
82 spin_unlock_irqrestore(&(ieee->reorder_spinlock),
86 rtllib_indicate_packets(ieee, ieee->stats_IndicateArray, index);
90 if (bPktInBuf && (pRxTs->RxTimeoutIndicateSeq == 0xffff)) {
91 pRxTs->RxTimeoutIndicateSeq = pRxTs->RxIndicateSeq;
92 mod_timer(&pRxTs->RxPktPendingTimer, jiffies +
93 msecs_to_jiffies(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 netdev_dbg(ieee->dev, "%s(): ADDBA Req is started\n", __func__);
110 static void ResetTsCommonInfo(struct ts_common_info *pTsCommonInfo)
112 eth_zero_addr(pTsCommonInfo->Addr);
113 memset(&pTsCommonInfo->TSpec, 0, sizeof(union tspec_body));
114 memset(&pTsCommonInfo->TClass, 0, sizeof(union qos_tclas)*TCLAS_NUM);
115 pTsCommonInfo->TClasProc = 0;
116 pTsCommonInfo->TClasNum = 0;
119 static void ResetTxTsEntry(struct tx_ts_record *pTS)
121 ResetTsCommonInfo(&pTS->TsCommonInfo);
123 pTS->bAddBaReqInProgress = false;
124 pTS->bAddBaReqDelayed = false;
125 pTS->bUsingBa = false;
126 pTS->bDisable_AddBa = false;
127 ResetBaEntry(&pTS->TxAdmittedBARecord);
128 ResetBaEntry(&pTS->TxPendingBARecord);
131 static void ResetRxTsEntry(struct rx_ts_record *pTS)
133 ResetTsCommonInfo(&pTS->TsCommonInfo);
134 pTS->RxIndicateSeq = 0xffff;
135 pTS->RxTimeoutIndicateSeq = 0xffff;
136 ResetBaEntry(&pTS->RxAdmittedBARecord);
139 void TSInitialize(struct rtllib_device *ieee)
141 struct tx_ts_record *pTxTS = ieee->TxTsRecord;
142 struct rx_ts_record *pRxTS = ieee->RxTsRecord;
143 struct rx_reorder_entry *pRxReorderEntry = ieee->RxReorderEntry;
146 netdev_vdbg(ieee->dev, "%s()\n", __func__);
147 INIT_LIST_HEAD(&ieee->Tx_TS_Admit_List);
148 INIT_LIST_HEAD(&ieee->Tx_TS_Pending_List);
149 INIT_LIST_HEAD(&ieee->Tx_TS_Unused_List);
151 for (count = 0; count < TOTAL_TS_NUM; count++) {
153 setup_timer(&pTxTS->TsCommonInfo.SetupTimer,
155 (unsigned long) pTxTS);
157 setup_timer(&pTxTS->TsCommonInfo.InactTimer,
159 (unsigned long) pTxTS);
161 setup_timer(&pTxTS->TsAddBaTimer,
163 (unsigned long) pTxTS);
165 setup_timer(&pTxTS->TxPendingBARecord.Timer,
167 (unsigned long) pTxTS);
168 setup_timer(&pTxTS->TxAdmittedBARecord.Timer,
170 (unsigned long) pTxTS);
172 ResetTxTsEntry(pTxTS);
173 list_add_tail(&pTxTS->TsCommonInfo.List,
174 &ieee->Tx_TS_Unused_List);
178 INIT_LIST_HEAD(&ieee->Rx_TS_Admit_List);
179 INIT_LIST_HEAD(&ieee->Rx_TS_Pending_List);
180 INIT_LIST_HEAD(&ieee->Rx_TS_Unused_List);
181 for (count = 0; count < TOTAL_TS_NUM; count++) {
183 INIT_LIST_HEAD(&pRxTS->RxPendingPktList);
185 setup_timer(&pRxTS->TsCommonInfo.SetupTimer,
187 (unsigned long) pRxTS);
189 setup_timer(&pRxTS->TsCommonInfo.InactTimer,
191 (unsigned long) pRxTS);
193 setup_timer(&pRxTS->RxAdmittedBARecord.Timer,
195 (unsigned long) pRxTS);
197 setup_timer(&pRxTS->RxPktPendingTimer,
199 (unsigned long) pRxTS);
201 ResetRxTsEntry(pRxTS);
202 list_add_tail(&pRxTS->TsCommonInfo.List,
203 &ieee->Rx_TS_Unused_List);
206 INIT_LIST_HEAD(&ieee->RxReorder_Unused_List);
207 for (count = 0; count < REORDER_ENTRY_NUM; count++) {
208 list_add_tail(&pRxReorderEntry->List,
209 &ieee->RxReorder_Unused_List);
210 if (count == (REORDER_ENTRY_NUM-1))
212 pRxReorderEntry = &ieee->RxReorderEntry[count+1];
217 static void AdmitTS(struct rtllib_device *ieee,
218 struct ts_common_info *pTsCommonInfo, u32 InactTime)
220 del_timer_sync(&pTsCommonInfo->SetupTimer);
221 del_timer_sync(&pTsCommonInfo->InactTimer);
224 mod_timer(&pTsCommonInfo->InactTimer, jiffies +
225 msecs_to_jiffies(InactTime));
228 static struct ts_common_info *SearchAdmitTRStream(struct rtllib_device *ieee,
230 enum tr_select TxRxSelect)
233 bool search_dir[4] = {0};
234 struct list_head *psearch_list;
235 struct ts_common_info *pRet = NULL;
237 if (ieee->iw_mode == IW_MODE_MASTER) {
238 if (TxRxSelect == TX_DIR) {
239 search_dir[DIR_DOWN] = true;
240 search_dir[DIR_BI_DIR] = true;
242 search_dir[DIR_UP] = true;
243 search_dir[DIR_BI_DIR] = true;
245 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
246 if (TxRxSelect == TX_DIR)
247 search_dir[DIR_UP] = true;
249 search_dir[DIR_DOWN] = true;
251 if (TxRxSelect == TX_DIR) {
252 search_dir[DIR_UP] = true;
253 search_dir[DIR_BI_DIR] = true;
254 search_dir[DIR_DIRECT] = true;
256 search_dir[DIR_DOWN] = true;
257 search_dir[DIR_BI_DIR] = true;
258 search_dir[DIR_DIRECT] = true;
262 if (TxRxSelect == TX_DIR)
263 psearch_list = &ieee->Tx_TS_Admit_List;
265 psearch_list = &ieee->Rx_TS_Admit_List;
267 for (dir = 0; dir <= DIR_BI_DIR; dir++) {
268 if (!search_dir[dir])
270 list_for_each_entry(pRet, psearch_list, List) {
271 if (memcmp(pRet->Addr, Addr, 6) == 0 &&
272 pRet->TSpec.f.TSInfo.field.ucTSID == TID &&
273 pRet->TSpec.f.TSInfo.field.ucDirection == dir)
277 if (&pRet->List != psearch_list)
281 if (pRet && &pRet->List != psearch_list)
286 static void MakeTSEntry(struct ts_common_info *pTsCommonInfo, u8 *Addr,
287 union tspec_body *pTSPEC, union qos_tclas *pTCLAS,
288 u8 TCLAS_Num, u8 TCLAS_Proc)
292 if (pTsCommonInfo == NULL)
295 memcpy(pTsCommonInfo->Addr, Addr, 6);
298 memcpy((u8 *)(&(pTsCommonInfo->TSpec)), (u8 *)pTSPEC,
299 sizeof(union tspec_body));
301 for (count = 0; count < TCLAS_Num; count++)
302 memcpy((u8 *)(&(pTsCommonInfo->TClass[count])),
303 (u8 *)pTCLAS, sizeof(union qos_tclas));
305 pTsCommonInfo->TClasProc = TCLAS_Proc;
306 pTsCommonInfo->TClasNum = TCLAS_Num;
309 bool GetTs(struct rtllib_device *ieee, struct ts_common_info **ppTS,
310 u8 *Addr, u8 TID, enum tr_select TxRxSelect, bool bAddNewTs)
313 union tspec_body TSpec;
314 union qos_tsinfo *pTSInfo = &TSpec.f.TSInfo;
315 struct list_head *pUnusedList;
316 struct list_head *pAddmitList;
317 enum direction_value Dir;
319 if (is_multicast_ether_addr(Addr)) {
320 netdev_warn(ieee->dev, "Get TS for Broadcast or Multicast\n");
323 if (ieee->current_network.qos_data.supported == 0) {
344 netdev_warn(ieee->dev, "%s(): TID(%d) is not valid\n",
350 *ppTS = SearchAdmitTRStream(ieee, Addr, UP, TxRxSelect);
355 netdev_dbg(ieee->dev, "add new TS failed(tid:%d)\n", UP);
359 pUnusedList = (TxRxSelect == TX_DIR) ?
360 (&ieee->Tx_TS_Unused_List) :
361 (&ieee->Rx_TS_Unused_List);
363 pAddmitList = (TxRxSelect == TX_DIR) ?
364 (&ieee->Tx_TS_Admit_List) :
365 (&ieee->Rx_TS_Admit_List);
367 Dir = (ieee->iw_mode == IW_MODE_MASTER) ?
368 ((TxRxSelect == TX_DIR) ? DIR_DOWN : DIR_UP) :
369 ((TxRxSelect == TX_DIR) ? DIR_UP : DIR_DOWN);
371 if (!list_empty(pUnusedList)) {
372 (*ppTS) = list_entry(pUnusedList->next,
373 struct ts_common_info, List);
374 list_del_init(&(*ppTS)->List);
375 if (TxRxSelect == TX_DIR) {
376 struct tx_ts_record *tmp =
382 struct rx_ts_record *tmp =
389 netdev_dbg(ieee->dev,
390 "to init current TS, UP:%d, Dir:%d, addr: %pM ppTs=%p\n",
391 UP, Dir, Addr, *ppTS);
392 pTSInfo->field.ucTrafficType = 0;
393 pTSInfo->field.ucTSID = UP;
394 pTSInfo->field.ucDirection = Dir;
395 pTSInfo->field.ucAccessPolicy = 1;
396 pTSInfo->field.ucAggregation = 0;
397 pTSInfo->field.ucPSB = 0;
398 pTSInfo->field.ucUP = UP;
399 pTSInfo->field.ucTSInfoAckPolicy = 0;
400 pTSInfo->field.ucSchedule = 0;
402 MakeTSEntry(*ppTS, Addr, &TSpec, NULL, 0, 0);
403 AdmitTS(ieee, *ppTS, 0);
404 list_add_tail(&((*ppTS)->List), pAddmitList);
409 netdev_warn(ieee->dev,
410 "There is not enough dir=%d(0=up down=1) TS record to be used!",
415 static void RemoveTsEntry(struct rtllib_device *ieee,
416 struct ts_common_info *pTs, enum tr_select TxRxSelect)
418 del_timer_sync(&pTs->SetupTimer);
419 del_timer_sync(&pTs->InactTimer);
420 TsInitDelBA(ieee, pTs, TxRxSelect);
422 if (TxRxSelect == RX_DIR) {
423 struct rx_reorder_entry *pRxReorderEntry;
424 struct rx_ts_record *pRxTS = (struct rx_ts_record *)pTs;
426 if (timer_pending(&pRxTS->RxPktPendingTimer))
427 del_timer_sync(&pRxTS->RxPktPendingTimer);
429 while (!list_empty(&pRxTS->RxPendingPktList)) {
430 pRxReorderEntry = (struct rx_reorder_entry *)
431 list_entry(pRxTS->RxPendingPktList.prev,
432 struct rx_reorder_entry, List);
433 netdev_dbg(ieee->dev, "%s(): Delete SeqNum %d!\n",
434 __func__, pRxReorderEntry->SeqNum);
435 list_del_init(&pRxReorderEntry->List);
438 struct rtllib_rxb *prxb = pRxReorderEntry->prxb;
442 for (i = 0; i < prxb->nr_subframes; i++)
443 dev_kfree_skb(prxb->subframes[i]);
447 list_add_tail(&pRxReorderEntry->List,
448 &ieee->RxReorder_Unused_List);
451 struct tx_ts_record *pTxTS = (struct tx_ts_record *)pTs;
453 del_timer_sync(&pTxTS->TsAddBaTimer);
457 void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr)
459 struct ts_common_info *pTS, *pTmpTS;
461 netdev_info(ieee->dev, "===========>RemovePeerTS, %pM\n", Addr);
463 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List) {
464 if (memcmp(pTS->Addr, Addr, 6) == 0) {
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->Tx_TS_Admit_List, List) {
472 if (memcmp(pTS->Addr, Addr, 6) == 0) {
473 netdev_info(ieee->dev,
474 "====>remove Tx_TS_admin_list\n");
475 RemoveTsEntry(ieee, pTS, TX_DIR);
476 list_del_init(&pTS->List);
477 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
481 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List) {
482 if (memcmp(pTS->Addr, Addr, 6) == 0) {
483 RemoveTsEntry(ieee, pTS, RX_DIR);
484 list_del_init(&pTS->List);
485 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
489 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_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 EXPORT_SYMBOL(RemovePeerTS);
499 void RemoveAllTS(struct rtllib_device *ieee)
501 struct ts_common_info *pTS, *pTmpTS;
503 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List) {
504 RemoveTsEntry(ieee, pTS, TX_DIR);
505 list_del_init(&pTS->List);
506 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
509 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List) {
510 RemoveTsEntry(ieee, pTS, TX_DIR);
511 list_del_init(&pTS->List);
512 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
515 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List) {
516 RemoveTsEntry(ieee, pTS, RX_DIR);
517 list_del_init(&pTS->List);
518 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
521 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List) {
522 RemoveTsEntry(ieee, pTS, RX_DIR);
523 list_del_init(&pTS->List);
524 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
528 void TsStartAddBaProcess(struct rtllib_device *ieee, struct tx_ts_record *pTxTS)
530 if (pTxTS->bAddBaReqInProgress == false) {
531 pTxTS->bAddBaReqInProgress = true;
533 if (pTxTS->bAddBaReqDelayed) {
534 netdev_dbg(ieee->dev, "Start ADDBA after 60 sec!!\n");
535 mod_timer(&pTxTS->TsAddBaTimer, jiffies +
536 msecs_to_jiffies(TS_ADDBA_DELAY));
538 netdev_dbg(ieee->dev, "Immediately Start ADDBA\n");
539 mod_timer(&pTxTS->TsAddBaTimer, jiffies+10);
542 netdev_dbg(ieee->dev, "BA timer is already added\n");