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;
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) {
46 while (!list_empty(&pRxTs
->RxPendingPktList
)) {
47 pReorderEntry
= (struct rx_reorder_entry
*)
48 list_entry(pRxTs
->RxPendingPktList
.prev
,
49 struct rx_reorder_entry
, List
);
51 pRxTs
->RxIndicateSeq
= pReorderEntry
->SeqNum
;
53 if (SN_LESS(pReorderEntry
->SeqNum
, pRxTs
->RxIndicateSeq
) ||
54 SN_EQUAL(pReorderEntry
->SeqNum
, pRxTs
->RxIndicateSeq
)) {
55 list_del_init(&pReorderEntry
->List
);
57 if (SN_EQUAL(pReorderEntry
->SeqNum
,
58 pRxTs
->RxIndicateSeq
))
59 pRxTs
->RxIndicateSeq
=
60 (pRxTs
->RxIndicateSeq
+ 1) % 4096;
62 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): Indicate"
63 " SeqNum: %d\n", __func__
,
64 pReorderEntry
->SeqNum
);
65 stats_IndicateArray
[index
] =
69 list_add_tail(&pReorderEntry
->List
,
70 &ieee
->RxReorder_Unused_List
);
79 pRxTs
->RxTimeoutIndicateSeq
= 0xffff;
81 if (index
> REORDER_WIN_SIZE
) {
82 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "RxReorderIndicatePacket():"
83 " Rx Reorer struct buffer full!!\n");
84 spin_unlock_irqrestore(&(ieee
->reorder_spinlock
),
88 rtllib_indicate_packets(ieee
, stats_IndicateArray
, index
);
92 if (bPktInBuf
&& (pRxTs
->RxTimeoutIndicateSeq
== 0xffff)) {
93 pRxTs
->RxTimeoutIndicateSeq
= pRxTs
->RxIndicateSeq
;
94 mod_timer(&pRxTs
->RxPktPendingTimer
, jiffies
+
95 MSECS(ieee
->pHTInfo
->RxReorderPendingTime
));
97 spin_unlock_irqrestore(&(ieee
->reorder_spinlock
), flags
);
100 static void TsAddBaProcess(unsigned long data
)
102 struct tx_ts_record
*pTxTs
= (struct tx_ts_record
*)data
;
104 struct rtllib_device
*ieee
= container_of(pTxTs
, struct rtllib_device
,
107 TsInitAddBA(ieee
, pTxTs
, BA_POLICY_IMMEDIATE
, false);
108 RTLLIB_DEBUG(RTLLIB_DL_BA
, "TsAddBaProcess(): ADDBA Req is "
112 static void ResetTsCommonInfo(struct ts_common_info
*pTsCommonInfo
)
114 memset(pTsCommonInfo
->Addr
, 0, 6);
115 memset(&pTsCommonInfo
->TSpec
, 0, sizeof(union tspec_body
));
116 memset(&pTsCommonInfo
->TClass
, 0, sizeof(union qos_tclas
)*TCLAS_NUM
);
117 pTsCommonInfo
->TClasProc
= 0;
118 pTsCommonInfo
->TClasNum
= 0;
121 static void ResetTxTsEntry(struct tx_ts_record
*pTS
)
123 ResetTsCommonInfo(&pTS
->TsCommonInfo
);
125 pTS
->bAddBaReqInProgress
= false;
126 pTS
->bAddBaReqDelayed
= false;
127 pTS
->bUsingBa
= false;
128 pTS
->bDisable_AddBa
= false;
129 ResetBaEntry(&pTS
->TxAdmittedBARecord
);
130 ResetBaEntry(&pTS
->TxPendingBARecord
);
133 static void ResetRxTsEntry(struct rx_ts_record
*pTS
)
135 ResetTsCommonInfo(&pTS
->TsCommonInfo
);
136 pTS
->RxIndicateSeq
= 0xffff;
137 pTS
->RxTimeoutIndicateSeq
= 0xffff;
138 ResetBaEntry(&pTS
->RxAdmittedBARecord
);
141 void TSInitialize(struct rtllib_device
*ieee
)
143 struct tx_ts_record
*pTxTS
= ieee
->TxTsRecord
;
144 struct rx_ts_record
*pRxTS
= ieee
->RxTsRecord
;
145 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
;
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
] == false)
270 list_for_each_entry(pRet
, psearch_list
, List
) {
271 if (memcmp(pRet
->Addr
, Addr
, 6) == 0)
272 if (pRet
->TSpec
.f
.TSInfo
.field
.ucTSID
== TID
)
273 if (pRet
->TSpec
.f
.TSInfo
.field
.ucDirection
== dir
)
277 if (&pRet
->List
!= psearch_list
)
281 if (&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
)
314 if (is_broadcast_ether_addr(Addr
) || is_multicast_ether_addr(Addr
)) {
315 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "ERR! get TS for Broadcast or "
319 if (ieee
->current_network
.qos_data
.supported
== 0) {
322 if (!IsACValid(TID
)) {
323 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "ERR! in %s(), TID(%d) is "
324 "not valid\n", __func__
, TID
);
348 *ppTS
= SearchAdmitTRStream(ieee
, Addr
, UP
, TxRxSelect
);
352 if (bAddNewTs
== false) {
353 RTLLIB_DEBUG(RTLLIB_DL_TS
, "add new TS failed"
357 union tspec_body TSpec
;
358 union qos_tsinfo
*pTSInfo
= &TSpec
.f
.TSInfo
;
359 struct list_head
*pUnusedList
=
360 (TxRxSelect
== TX_DIR
) ?
361 (&ieee
->Tx_TS_Unused_List
) :
362 (&ieee
->Rx_TS_Unused_List
);
364 struct list_head
*pAddmitList
=
365 (TxRxSelect
== TX_DIR
) ?
366 (&ieee
->Tx_TS_Admit_List
) :
367 (&ieee
->Rx_TS_Admit_List
);
369 enum direction_value Dir
=
370 (ieee
->iw_mode
== IW_MODE_MASTER
) ?
371 ((TxRxSelect
== TX_DIR
) ? DIR_DOWN
: DIR_UP
) :
372 ((TxRxSelect
== TX_DIR
) ? DIR_UP
: DIR_DOWN
);
373 RTLLIB_DEBUG(RTLLIB_DL_TS
, "to add Ts\n");
374 if (!list_empty(pUnusedList
)) {
375 (*ppTS
) = list_entry(pUnusedList
->next
,
376 struct ts_common_info
, List
);
377 list_del_init(&(*ppTS
)->List
);
378 if (TxRxSelect
== TX_DIR
) {
379 struct tx_ts_record
*tmp
=
385 struct rx_ts_record
*tmp
=
392 RTLLIB_DEBUG(RTLLIB_DL_TS
, "to init current TS"
393 ", UP:%d, Dir:%d, addr: %pM"
394 " ppTs=%p\n", UP
, Dir
,
396 pTSInfo
->field
.ucTrafficType
= 0;
397 pTSInfo
->field
.ucTSID
= UP
;
398 pTSInfo
->field
.ucDirection
= Dir
;
399 pTSInfo
->field
.ucAccessPolicy
= 1;
400 pTSInfo
->field
.ucAggregation
= 0;
401 pTSInfo
->field
.ucPSB
= 0;
402 pTSInfo
->field
.ucUP
= UP
;
403 pTSInfo
->field
.ucTSInfoAckPolicy
= 0;
404 pTSInfo
->field
.ucSchedule
= 0;
406 MakeTSEntry(*ppTS
, Addr
, &TSpec
, NULL
, 0, 0);
407 AdmitTS(ieee
, *ppTS
, 0);
408 list_add_tail(&((*ppTS
)->List
), pAddmitList
);
412 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "ERR!!in function "
413 "%s() There is not enough dir=%d"
414 "(0=up down=1) TS record to be "
415 "used!!", __func__
, Dir
);
422 static void RemoveTsEntry(struct rtllib_device
*ieee
, struct ts_common_info
*pTs
,
423 enum tr_select TxRxSelect
)
425 del_timer_sync(&pTs
->SetupTimer
);
426 del_timer_sync(&pTs
->InactTimer
);
427 TsInitDelBA(ieee
, pTs
, TxRxSelect
);
429 if (TxRxSelect
== RX_DIR
) {
430 struct rx_reorder_entry
*pRxReorderEntry
;
431 struct rx_ts_record
*pRxTS
= (struct rx_ts_record
*)pTs
;
433 if (timer_pending(&pRxTS
->RxPktPendingTimer
))
434 del_timer_sync(&pRxTS
->RxPktPendingTimer
);
436 while (!list_empty(&pRxTS
->RxPendingPktList
)) {
437 pRxReorderEntry
= (struct rx_reorder_entry
*)
438 list_entry(pRxTS
->RxPendingPktList
.prev
,
439 struct rx_reorder_entry
, List
);
440 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): Delete SeqNum "
442 pRxReorderEntry
->SeqNum
);
443 list_del_init(&pRxReorderEntry
->List
);
446 struct rtllib_rxb
*prxb
= pRxReorderEntry
->prxb
;
449 for (i
= 0; i
< prxb
->nr_subframes
; i
++)
450 dev_kfree_skb(prxb
->subframes
[i
]);
454 list_add_tail(&pRxReorderEntry
->List
,
455 &ieee
->RxReorder_Unused_List
);
458 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
;
466 printk(KERN_INFO
"===========>RemovePeerTS, %pM\n", Addr
);
468 list_for_each_entry_safe(pTS
, pTmpTS
, &ieee
->Tx_TS_Pending_List
, List
) {
469 if (memcmp(pTS
->Addr
, Addr
, 6) == 0) {
470 RemoveTsEntry(ieee
, pTS
, TX_DIR
);
471 list_del_init(&pTS
->List
);
472 list_add_tail(&pTS
->List
, &ieee
->Tx_TS_Unused_List
);
476 list_for_each_entry_safe(pTS
, pTmpTS
, &ieee
->Tx_TS_Admit_List
, List
) {
477 if (memcmp(pTS
->Addr
, Addr
, 6) == 0) {
478 printk(KERN_INFO
"====>remove Tx_TS_admin_list\n");
479 RemoveTsEntry(ieee
, pTS
, TX_DIR
);
480 list_del_init(&pTS
->List
);
481 list_add_tail(&pTS
->List
, &ieee
->Tx_TS_Unused_List
);
485 list_for_each_entry_safe(pTS
, pTmpTS
, &ieee
->Rx_TS_Pending_List
, List
) {
486 if (memcmp(pTS
->Addr
, Addr
, 6) == 0) {
487 RemoveTsEntry(ieee
, pTS
, RX_DIR
);
488 list_del_init(&pTS
->List
);
489 list_add_tail(&pTS
->List
, &ieee
->Rx_TS_Unused_List
);
493 list_for_each_entry_safe(pTS
, pTmpTS
, &ieee
->Rx_TS_Admit_List
, List
) {
494 if (memcmp(pTS
->Addr
, Addr
, 6) == 0) {
495 RemoveTsEntry(ieee
, pTS
, RX_DIR
);
496 list_del_init(&pTS
->List
);
497 list_add_tail(&pTS
->List
, &ieee
->Rx_TS_Unused_List
);
502 void RemoveAllTS(struct rtllib_device
*ieee
)
504 struct ts_common_info
*pTS
, *pTmpTS
;
506 list_for_each_entry_safe(pTS
, pTmpTS
, &ieee
->Tx_TS_Pending_List
, List
) {
507 RemoveTsEntry(ieee
, pTS
, TX_DIR
);
508 list_del_init(&pTS
->List
);
509 list_add_tail(&pTS
->List
, &ieee
->Tx_TS_Unused_List
);
512 list_for_each_entry_safe(pTS
, pTmpTS
, &ieee
->Tx_TS_Admit_List
, List
) {
513 RemoveTsEntry(ieee
, pTS
, TX_DIR
);
514 list_del_init(&pTS
->List
);
515 list_add_tail(&pTS
->List
, &ieee
->Tx_TS_Unused_List
);
518 list_for_each_entry_safe(pTS
, pTmpTS
, &ieee
->Rx_TS_Pending_List
, List
) {
519 RemoveTsEntry(ieee
, pTS
, RX_DIR
);
520 list_del_init(&pTS
->List
);
521 list_add_tail(&pTS
->List
, &ieee
->Rx_TS_Unused_List
);
524 list_for_each_entry_safe(pTS
, pTmpTS
, &ieee
->Rx_TS_Admit_List
, List
) {
525 RemoveTsEntry(ieee
, pTS
, RX_DIR
);
526 list_del_init(&pTS
->List
);
527 list_add_tail(&pTS
->List
, &ieee
->Rx_TS_Unused_List
);
531 void TsStartAddBaProcess(struct rtllib_device
*ieee
, struct tx_ts_record
*pTxTS
)
533 if (pTxTS
->bAddBaReqInProgress
== false) {
534 pTxTS
->bAddBaReqInProgress
= true;
536 if (pTxTS
->bAddBaReqDelayed
) {
537 RTLLIB_DEBUG(RTLLIB_DL_BA
, "TsStartAddBaProcess(): "
538 "Delayed Start ADDBA after 60 sec!!\n");
539 mod_timer(&pTxTS
->TsAddBaTimer
, jiffies
+
540 MSECS(TS_ADDBA_DELAY
));
542 RTLLIB_DEBUG(RTLLIB_DL_BA
, "TsStartAddBaProcess(): "
543 "Immediately Start ADDBA now!!\n");
544 mod_timer(&pTxTS
->TsAddBaTimer
, jiffies
+10);
547 RTLLIB_DEBUG(RTLLIB_DL_BA
, "%s()==>BA timer is already added\n",