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,
53 pRxTs->RxIndicateSeq) ||
54 SN_EQUAL(pReorderEntry->SeqNum,
55 pRxTs->RxIndicateSeq)) {
56 list_del_init(&pReorderEntry->List);
58 if (SN_EQUAL(pReorderEntry->SeqNum,
59 pRxTs->RxIndicateSeq))
60 pRxTs->RxIndicateSeq =
61 (pRxTs->RxIndicateSeq + 1) % 4096;
64 "%s(): Indicate SeqNum: %d\n",
65 __func__, pReorderEntry->SeqNum);
66 ieee->stats_IndicateArray[index] =
70 list_add_tail(&pReorderEntry->List,
71 &ieee->RxReorder_Unused_List);
80 pRxTs->RxTimeoutIndicateSeq = 0xffff;
82 if (index > REORDER_WIN_SIZE) {
83 netdev_warn(ieee->dev,
84 "%s(): Rx Reorder struct buffer full\n",
86 spin_unlock_irqrestore(&(ieee->reorder_spinlock),
90 rtllib_indicate_packets(ieee, ieee->stats_IndicateArray, index);
94 if (bPktInBuf && (pRxTs->RxTimeoutIndicateSeq == 0xffff)) {
95 pRxTs->RxTimeoutIndicateSeq = pRxTs->RxIndicateSeq;
96 mod_timer(&pRxTs->RxPktPendingTimer, jiffies +
97 msecs_to_jiffies(ieee->pHTInfo->RxReorderPendingTime)
100 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
103 static void TsAddBaProcess(unsigned long data)
105 struct tx_ts_record *pTxTs = (struct tx_ts_record *)data;
107 struct rtllib_device *ieee = container_of(pTxTs, struct rtllib_device,
110 TsInitAddBA(ieee, pTxTs, BA_POLICY_IMMEDIATE, false);
111 netdev_dbg(ieee->dev, "%s(): ADDBA Req is started\n", __func__);
114 static void ResetTsCommonInfo(struct ts_common_info *pTsCommonInfo)
116 memset(pTsCommonInfo->Addr, 0, 6);
117 memset(&pTsCommonInfo->TSpec, 0, sizeof(union tspec_body));
118 memset(&pTsCommonInfo->TClass, 0, sizeof(union qos_tclas)*TCLAS_NUM);
119 pTsCommonInfo->TClasProc = 0;
120 pTsCommonInfo->TClasNum = 0;
123 static void ResetTxTsEntry(struct tx_ts_record *pTS)
125 ResetTsCommonInfo(&pTS->TsCommonInfo);
127 pTS->bAddBaReqInProgress = false;
128 pTS->bAddBaReqDelayed = false;
129 pTS->bUsingBa = false;
130 pTS->bDisable_AddBa = false;
131 ResetBaEntry(&pTS->TxAdmittedBARecord);
132 ResetBaEntry(&pTS->TxPendingBARecord);
135 static void ResetRxTsEntry(struct rx_ts_record *pTS)
137 ResetTsCommonInfo(&pTS->TsCommonInfo);
138 pTS->RxIndicateSeq = 0xffff;
139 pTS->RxTimeoutIndicateSeq = 0xffff;
140 ResetBaEntry(&pTS->RxAdmittedBARecord);
143 void TSInitialize(struct rtllib_device *ieee)
145 struct tx_ts_record *pTxTS = ieee->TxTsRecord;
146 struct rx_ts_record *pRxTS = ieee->RxTsRecord;
147 struct rx_reorder_entry *pRxReorderEntry = ieee->RxReorderEntry;
150 netdev_vdbg(ieee->dev, "%s()\n", __func__);
151 INIT_LIST_HEAD(&ieee->Tx_TS_Admit_List);
152 INIT_LIST_HEAD(&ieee->Tx_TS_Pending_List);
153 INIT_LIST_HEAD(&ieee->Tx_TS_Unused_List);
155 for (count = 0; count < TOTAL_TS_NUM; count++) {
157 setup_timer(&pTxTS->TsCommonInfo.SetupTimer,
159 (unsigned long) pTxTS);
161 setup_timer(&pTxTS->TsCommonInfo.InactTimer,
163 (unsigned long) pTxTS);
165 setup_timer(&pTxTS->TsAddBaTimer,
167 (unsigned long) pTxTS);
169 setup_timer(&pTxTS->TxPendingBARecord.Timer,
171 (unsigned long) pTxTS);
172 setup_timer(&pTxTS->TxAdmittedBARecord.Timer,
174 (unsigned long) pTxTS);
176 ResetTxTsEntry(pTxTS);
177 list_add_tail(&pTxTS->TsCommonInfo.List,
178 &ieee->Tx_TS_Unused_List);
182 INIT_LIST_HEAD(&ieee->Rx_TS_Admit_List);
183 INIT_LIST_HEAD(&ieee->Rx_TS_Pending_List);
184 INIT_LIST_HEAD(&ieee->Rx_TS_Unused_List);
185 for (count = 0; count < TOTAL_TS_NUM; count++) {
187 INIT_LIST_HEAD(&pRxTS->RxPendingPktList);
189 setup_timer(&pRxTS->TsCommonInfo.SetupTimer,
191 (unsigned long) pRxTS);
193 setup_timer(&pRxTS->TsCommonInfo.InactTimer,
195 (unsigned long) pRxTS);
197 setup_timer(&pRxTS->RxAdmittedBARecord.Timer,
199 (unsigned long) pRxTS);
201 setup_timer(&pRxTS->RxPktPendingTimer,
203 (unsigned long) pRxTS);
205 ResetRxTsEntry(pRxTS);
206 list_add_tail(&pRxTS->TsCommonInfo.List,
207 &ieee->Rx_TS_Unused_List);
210 INIT_LIST_HEAD(&ieee->RxReorder_Unused_List);
211 for (count = 0; count < REORDER_ENTRY_NUM; count++) {
212 list_add_tail(&pRxReorderEntry->List,
213 &ieee->RxReorder_Unused_List);
214 if (count == (REORDER_ENTRY_NUM-1))
216 pRxReorderEntry = &ieee->RxReorderEntry[count+1];
221 static void AdmitTS(struct rtllib_device *ieee,
222 struct ts_common_info *pTsCommonInfo, u32 InactTime)
224 del_timer_sync(&pTsCommonInfo->SetupTimer);
225 del_timer_sync(&pTsCommonInfo->InactTimer);
228 mod_timer(&pTsCommonInfo->InactTimer, jiffies +
229 msecs_to_jiffies(InactTime));
232 static struct ts_common_info *SearchAdmitTRStream(struct rtllib_device *ieee,
234 enum tr_select TxRxSelect)
237 bool search_dir[4] = {0};
238 struct list_head *psearch_list;
239 struct ts_common_info *pRet = NULL;
241 if (ieee->iw_mode == IW_MODE_MASTER) {
242 if (TxRxSelect == TX_DIR) {
243 search_dir[DIR_DOWN] = true;
244 search_dir[DIR_BI_DIR] = true;
246 search_dir[DIR_UP] = true;
247 search_dir[DIR_BI_DIR] = true;
249 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
250 if (TxRxSelect == TX_DIR)
251 search_dir[DIR_UP] = true;
253 search_dir[DIR_DOWN] = true;
255 if (TxRxSelect == TX_DIR) {
256 search_dir[DIR_UP] = true;
257 search_dir[DIR_BI_DIR] = true;
258 search_dir[DIR_DIRECT] = true;
260 search_dir[DIR_DOWN] = true;
261 search_dir[DIR_BI_DIR] = true;
262 search_dir[DIR_DIRECT] = true;
266 if (TxRxSelect == TX_DIR)
267 psearch_list = &ieee->Tx_TS_Admit_List;
269 psearch_list = &ieee->Rx_TS_Admit_List;
271 for (dir = 0; dir <= DIR_BI_DIR; dir++) {
272 if (!search_dir[dir])
274 list_for_each_entry(pRet, psearch_list, List) {
275 if (memcmp(pRet->Addr, Addr, 6) == 0 &&
276 pRet->TSpec.f.TSInfo.field.ucTSID == TID &&
277 pRet->TSpec.f.TSInfo.field.ucDirection == dir)
281 if (&pRet->List != psearch_list)
285 if (pRet && &pRet->List != psearch_list)
290 static void MakeTSEntry(struct ts_common_info *pTsCommonInfo, u8 *Addr,
291 union tspec_body *pTSPEC, union qos_tclas *pTCLAS,
292 u8 TCLAS_Num, u8 TCLAS_Proc)
296 if (pTsCommonInfo == NULL)
299 memcpy(pTsCommonInfo->Addr, Addr, 6);
302 memcpy((u8 *)(&(pTsCommonInfo->TSpec)), (u8 *)pTSPEC,
303 sizeof(union tspec_body));
305 for (count = 0; count < TCLAS_Num; count++)
306 memcpy((u8 *)(&(pTsCommonInfo->TClass[count])),
307 (u8 *)pTCLAS, sizeof(union qos_tclas));
309 pTsCommonInfo->TClasProc = TCLAS_Proc;
310 pTsCommonInfo->TClasNum = TCLAS_Num;
313 bool GetTs(struct rtllib_device *ieee, struct ts_common_info **ppTS,
314 u8 *Addr, u8 TID, enum tr_select TxRxSelect, bool bAddNewTs)
317 union tspec_body TSpec;
318 union qos_tsinfo *pTSInfo = &TSpec.f.TSInfo;
319 struct list_head *pUnusedList;
320 struct list_head *pAddmitList;
321 enum direction_value Dir;
323 if (is_multicast_ether_addr(Addr)) {
324 netdev_warn(ieee->dev, "Get TS for Broadcast or Multicast\n");
327 if (ieee->current_network.qos_data.supported == 0) {
330 if (!IsACValid(TID)) {
331 netdev_warn(ieee->dev, "%s(): TID(%d) is not valid\n",
356 *ppTS = SearchAdmitTRStream(ieee, Addr, UP, TxRxSelect);
361 netdev_dbg(ieee->dev, "add new TS failed(tid:%d)\n", UP);
365 pUnusedList = (TxRxSelect == TX_DIR) ?
366 (&ieee->Tx_TS_Unused_List) :
367 (&ieee->Rx_TS_Unused_List);
369 pAddmitList = (TxRxSelect == TX_DIR) ?
370 (&ieee->Tx_TS_Admit_List) :
371 (&ieee->Rx_TS_Admit_List);
373 Dir = (ieee->iw_mode == IW_MODE_MASTER) ?
374 ((TxRxSelect == TX_DIR) ? DIR_DOWN : DIR_UP) :
375 ((TxRxSelect == TX_DIR) ? DIR_UP : DIR_DOWN);
377 if (!list_empty(pUnusedList)) {
378 (*ppTS) = list_entry(pUnusedList->next,
379 struct ts_common_info, List);
380 list_del_init(&(*ppTS)->List);
381 if (TxRxSelect == TX_DIR) {
382 struct tx_ts_record *tmp =
388 struct rx_ts_record *tmp =
395 netdev_dbg(ieee->dev,
396 "to init current TS, UP:%d, Dir:%d, addr: %pM ppTs=%p\n",
397 UP, Dir, Addr, *ppTS);
398 pTSInfo->field.ucTrafficType = 0;
399 pTSInfo->field.ucTSID = UP;
400 pTSInfo->field.ucDirection = Dir;
401 pTSInfo->field.ucAccessPolicy = 1;
402 pTSInfo->field.ucAggregation = 0;
403 pTSInfo->field.ucPSB = 0;
404 pTSInfo->field.ucUP = UP;
405 pTSInfo->field.ucTSInfoAckPolicy = 0;
406 pTSInfo->field.ucSchedule = 0;
408 MakeTSEntry(*ppTS, Addr, &TSpec, NULL, 0, 0);
409 AdmitTS(ieee, *ppTS, 0);
410 list_add_tail(&((*ppTS)->List), pAddmitList);
415 netdev_warn(ieee->dev,
416 "There is not enough dir=%d(0=up down=1) TS record to be used!",
421 static void RemoveTsEntry(struct rtllib_device *ieee,
422 struct ts_common_info *pTs, enum tr_select TxRxSelect)
424 del_timer_sync(&pTs->SetupTimer);
425 del_timer_sync(&pTs->InactTimer);
426 TsInitDelBA(ieee, pTs, TxRxSelect);
428 if (TxRxSelect == RX_DIR) {
429 struct rx_reorder_entry *pRxReorderEntry;
430 struct rx_ts_record *pRxTS = (struct rx_ts_record *)pTs;
432 if (timer_pending(&pRxTS->RxPktPendingTimer))
433 del_timer_sync(&pRxTS->RxPktPendingTimer);
435 while (!list_empty(&pRxTS->RxPendingPktList)) {
436 pRxReorderEntry = (struct rx_reorder_entry *)
437 list_entry(pRxTS->RxPendingPktList.prev,
438 struct rx_reorder_entry, List);
439 netdev_dbg(ieee->dev, "%s(): Delete SeqNum %d!\n",
440 __func__, pRxReorderEntry->SeqNum);
441 list_del_init(&pRxReorderEntry->List);
444 struct rtllib_rxb *prxb = pRxReorderEntry->prxb;
448 for (i = 0; i < prxb->nr_subframes; i++)
449 dev_kfree_skb(prxb->subframes[i]);
453 list_add_tail(&pRxReorderEntry->List,
454 &ieee->RxReorder_Unused_List);
457 struct tx_ts_record *pTxTS = (struct tx_ts_record *)pTs;
459 del_timer_sync(&pTxTS->TsAddBaTimer);
463 void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr)
465 struct ts_common_info *pTS, *pTmpTS;
467 netdev_info(ieee->dev, "===========>RemovePeerTS, %pM\n", Addr);
469 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List) {
470 if (memcmp(pTS->Addr, Addr, 6) == 0) {
471 RemoveTsEntry(ieee, pTS, TX_DIR);
472 list_del_init(&pTS->List);
473 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
477 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List) {
478 if (memcmp(pTS->Addr, Addr, 6) == 0) {
479 netdev_info(ieee->dev,
480 "====>remove Tx_TS_admin_list\n");
481 RemoveTsEntry(ieee, pTS, TX_DIR);
482 list_del_init(&pTS->List);
483 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
487 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List) {
488 if (memcmp(pTS->Addr, Addr, 6) == 0) {
489 RemoveTsEntry(ieee, pTS, RX_DIR);
490 list_del_init(&pTS->List);
491 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
495 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List) {
496 if (memcmp(pTS->Addr, Addr, 6) == 0) {
497 RemoveTsEntry(ieee, pTS, RX_DIR);
498 list_del_init(&pTS->List);
499 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
503 EXPORT_SYMBOL(RemovePeerTS);
505 void RemoveAllTS(struct rtllib_device *ieee)
507 struct ts_common_info *pTS, *pTmpTS;
509 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_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->Tx_TS_Admit_List, List) {
516 RemoveTsEntry(ieee, pTS, TX_DIR);
517 list_del_init(&pTS->List);
518 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
521 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_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);
527 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List) {
528 RemoveTsEntry(ieee, pTS, RX_DIR);
529 list_del_init(&pTS->List);
530 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
534 void TsStartAddBaProcess(struct rtllib_device *ieee, struct tx_ts_record *pTxTS)
536 if (pTxTS->bAddBaReqInProgress == false) {
537 pTxTS->bAddBaReqInProgress = true;
539 if (pTxTS->bAddBaReqDelayed) {
540 netdev_dbg(ieee->dev, "Start ADDBA after 60 sec!!\n");
541 mod_timer(&pTxTS->TsAddBaTimer, jiffies +
542 msecs_to_jiffies(TS_ADDBA_DELAY));
544 netdev_dbg(ieee->dev, "Immediately Start ADDBA\n");
545 mod_timer(&pTxTS->TsAddBaTimer, jiffies+10);
548 netdev_dbg(ieee->dev, "BA timer is already added\n");