1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
5 * Contact Information: wlanfae <wlanfae@realtek.com>
8 #include <linux/etherdevice.h>
9 #include "rtl819x_TS.h"
11 static void RxPktPendingTimeout(struct timer_list *t)
13 struct rx_ts_record *pRxTs = from_timer(pRxTs, t,
14 rx_pkt_pending_timer);
15 struct rtllib_device *ieee = container_of(pRxTs, struct rtllib_device,
16 RxTsRecord[pRxTs->num]);
18 struct rx_reorder_entry *pReorderEntry = NULL;
20 unsigned long flags = 0;
22 bool bPktInBuf = false;
24 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
25 if (pRxTs->rx_timeout_indicate_seq != 0xffff) {
26 while (!list_empty(&pRxTs->rx_pending_pkt_list)) {
27 pReorderEntry = (struct rx_reorder_entry *)
28 list_entry(pRxTs->rx_pending_pkt_list.prev,
29 struct rx_reorder_entry, List);
31 pRxTs->rx_indicate_seq = pReorderEntry->SeqNum;
33 if (SN_LESS(pReorderEntry->SeqNum,
34 pRxTs->rx_indicate_seq) ||
35 SN_EQUAL(pReorderEntry->SeqNum,
36 pRxTs->rx_indicate_seq)) {
37 list_del_init(&pReorderEntry->List);
39 if (SN_EQUAL(pReorderEntry->SeqNum,
40 pRxTs->rx_indicate_seq))
41 pRxTs->rx_indicate_seq =
42 (pRxTs->rx_indicate_seq + 1) % 4096;
45 "%s(): Indicate SeqNum: %d\n",
46 __func__, pReorderEntry->SeqNum);
47 ieee->stats_IndicateArray[index] =
51 list_add_tail(&pReorderEntry->List,
52 &ieee->RxReorder_Unused_List);
61 pRxTs->rx_timeout_indicate_seq = 0xffff;
63 if (index > REORDER_WIN_SIZE) {
64 netdev_warn(ieee->dev,
65 "%s(): Rx Reorder struct buffer full\n",
67 spin_unlock_irqrestore(&(ieee->reorder_spinlock),
71 rtllib_indicate_packets(ieee, ieee->stats_IndicateArray, index);
75 if (bPktInBuf && (pRxTs->rx_timeout_indicate_seq == 0xffff)) {
76 pRxTs->rx_timeout_indicate_seq = pRxTs->rx_indicate_seq;
77 mod_timer(&pRxTs->rx_pkt_pending_timer, jiffies +
78 msecs_to_jiffies(ieee->ht_info->rx_reorder_pending_time)
81 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
84 static void TsAddBaProcess(struct timer_list *t)
86 struct tx_ts_record *pTxTs = from_timer(pTxTs, t, TsAddBaTimer);
88 struct rtllib_device *ieee = container_of(pTxTs, struct rtllib_device,
91 rtllib_ts_init_add_ba(ieee, pTxTs, BA_POLICY_IMMEDIATE, false);
92 netdev_dbg(ieee->dev, "%s(): ADDBA Req is started\n", __func__);
95 static void ResetTsCommonInfo(struct ts_common_info *pTsCommonInfo)
97 eth_zero_addr(pTsCommonInfo->Addr);
98 memset(&pTsCommonInfo->TSpec, 0, sizeof(union tspec_body));
99 memset(&pTsCommonInfo->TClass, 0, sizeof(union qos_tclas) * TCLAS_NUM);
100 pTsCommonInfo->TClasProc = 0;
101 pTsCommonInfo->TClasNum = 0;
104 static void ResetTxTsEntry(struct tx_ts_record *pTS)
106 ResetTsCommonInfo(&pTS->TsCommonInfo);
108 pTS->bAddBaReqInProgress = false;
109 pTS->bAddBaReqDelayed = false;
110 pTS->bUsingBa = false;
111 pTS->bDisable_AddBa = false;
112 rtllib_reset_ba_entry(&pTS->TxAdmittedBARecord);
113 rtllib_reset_ba_entry(&pTS->TxPendingBARecord);
116 static void ResetRxTsEntry(struct rx_ts_record *pTS)
118 ResetTsCommonInfo(&pTS->ts_common_info);
119 pTS->rx_indicate_seq = 0xffff;
120 pTS->rx_timeout_indicate_seq = 0xffff;
121 rtllib_reset_ba_entry(&pTS->rx_admitted_ba_record);
124 void TSInitialize(struct rtllib_device *ieee)
126 struct tx_ts_record *pTxTS = ieee->TxTsRecord;
127 struct rx_ts_record *pRxTS = ieee->RxTsRecord;
128 struct rx_reorder_entry *pRxReorderEntry = ieee->RxReorderEntry;
131 INIT_LIST_HEAD(&ieee->Tx_TS_Admit_List);
132 INIT_LIST_HEAD(&ieee->Tx_TS_Pending_List);
133 INIT_LIST_HEAD(&ieee->Tx_TS_Unused_List);
135 for (count = 0; count < TOTAL_TS_NUM; count++) {
137 timer_setup(&pTxTS->TsAddBaTimer, TsAddBaProcess, 0);
139 timer_setup(&pTxTS->TxPendingBARecord.timer, rtllib_ba_setup_timeout,
141 timer_setup(&pTxTS->TxAdmittedBARecord.timer,
142 rtllib_tx_ba_inact_timeout, 0);
144 ResetTxTsEntry(pTxTS);
145 list_add_tail(&pTxTS->TsCommonInfo.List,
146 &ieee->Tx_TS_Unused_List);
150 INIT_LIST_HEAD(&ieee->Rx_TS_Admit_List);
151 INIT_LIST_HEAD(&ieee->Rx_TS_Pending_List);
152 INIT_LIST_HEAD(&ieee->Rx_TS_Unused_List);
153 for (count = 0; count < TOTAL_TS_NUM; count++) {
155 INIT_LIST_HEAD(&pRxTS->rx_pending_pkt_list);
156 timer_setup(&pRxTS->rx_admitted_ba_record.timer,
157 rtllib_rx_ba_inact_timeout, 0);
159 timer_setup(&pRxTS->rx_pkt_pending_timer, RxPktPendingTimeout, 0);
161 ResetRxTsEntry(pRxTS);
162 list_add_tail(&pRxTS->ts_common_info.List,
163 &ieee->Rx_TS_Unused_List);
166 INIT_LIST_HEAD(&ieee->RxReorder_Unused_List);
167 for (count = 0; count < REORDER_ENTRY_NUM; count++) {
168 list_add_tail(&pRxReorderEntry->List,
169 &ieee->RxReorder_Unused_List);
170 if (count == (REORDER_ENTRY_NUM - 1))
172 pRxReorderEntry = &ieee->RxReorderEntry[count + 1];
176 static struct ts_common_info *SearchAdmitTRStream(struct rtllib_device *ieee,
178 enum tr_select TxRxSelect)
181 bool search_dir[4] = {0};
182 struct list_head *psearch_list;
183 struct ts_common_info *pRet = NULL;
185 if (ieee->iw_mode == IW_MODE_ADHOC) {
186 if (TxRxSelect == TX_DIR)
187 search_dir[DIR_UP] = true;
189 search_dir[DIR_DOWN] = true;
191 if (TxRxSelect == TX_DIR) {
192 search_dir[DIR_UP] = true;
193 search_dir[DIR_BI_DIR] = true;
194 search_dir[DIR_DIRECT] = true;
196 search_dir[DIR_DOWN] = true;
197 search_dir[DIR_BI_DIR] = true;
198 search_dir[DIR_DIRECT] = true;
202 if (TxRxSelect == TX_DIR)
203 psearch_list = &ieee->Tx_TS_Admit_List;
205 psearch_list = &ieee->Rx_TS_Admit_List;
207 for (dir = 0; dir <= DIR_BI_DIR; dir++) {
208 if (!search_dir[dir])
210 list_for_each_entry(pRet, psearch_list, List) {
211 if (memcmp(pRet->Addr, Addr, 6) == 0 &&
212 pRet->TSpec.f.TSInfo.field.ucTSID == TID &&
213 pRet->TSpec.f.TSInfo.field.ucDirection == dir)
216 if (&pRet->List != psearch_list)
220 if (pRet && &pRet->List != psearch_list)
225 static void MakeTSEntry(struct ts_common_info *pTsCommonInfo, u8 *Addr,
226 union tspec_body *pTSPEC, union qos_tclas *pTCLAS,
227 u8 TCLAS_Num, u8 TCLAS_Proc)
234 memcpy(pTsCommonInfo->Addr, Addr, 6);
237 memcpy((u8 *)(&(pTsCommonInfo->TSpec)), (u8 *)pTSPEC,
238 sizeof(union tspec_body));
240 for (count = 0; count < TCLAS_Num; count++)
241 memcpy((u8 *)(&(pTsCommonInfo->TClass[count])),
242 (u8 *)pTCLAS, sizeof(union qos_tclas));
244 pTsCommonInfo->TClasProc = TCLAS_Proc;
245 pTsCommonInfo->TClasNum = TCLAS_Num;
248 bool GetTs(struct rtllib_device *ieee, struct ts_common_info **ppTS,
249 u8 *Addr, u8 TID, enum tr_select TxRxSelect, bool bAddNewTs)
252 union tspec_body TSpec;
253 union qos_tsinfo *pTSInfo = &TSpec.f.TSInfo;
254 struct list_head *pUnusedList;
255 struct list_head *pAddmitList;
256 enum direction_value Dir;
258 if (is_multicast_ether_addr(Addr)) {
259 netdev_warn(ieee->dev, "Get TS for Broadcast or Multicast\n");
262 if (ieee->current_network.qos_data.supported == 0) {
283 netdev_warn(ieee->dev, "%s(): TID(%d) is not valid\n",
289 *ppTS = SearchAdmitTRStream(ieee, Addr, UP, TxRxSelect);
294 netdev_dbg(ieee->dev, "add new TS failed(tid:%d)\n", UP);
298 pUnusedList = (TxRxSelect == TX_DIR) ?
299 (&ieee->Tx_TS_Unused_List) :
300 (&ieee->Rx_TS_Unused_List);
302 pAddmitList = (TxRxSelect == TX_DIR) ?
303 (&ieee->Tx_TS_Admit_List) :
304 (&ieee->Rx_TS_Admit_List);
306 Dir = ((TxRxSelect == TX_DIR) ? DIR_UP : DIR_DOWN);
308 if (!list_empty(pUnusedList)) {
309 (*ppTS) = list_entry(pUnusedList->next,
310 struct ts_common_info, List);
311 list_del_init(&(*ppTS)->List);
312 if (TxRxSelect == TX_DIR) {
313 struct tx_ts_record *tmp =
319 struct rx_ts_record *tmp =
326 netdev_dbg(ieee->dev,
327 "to init current TS, UP:%d, Dir:%d, addr: %pM ppTs=%p\n",
328 UP, Dir, Addr, *ppTS);
329 pTSInfo->field.ucTrafficType = 0;
330 pTSInfo->field.ucTSID = UP;
331 pTSInfo->field.ucDirection = Dir;
332 pTSInfo->field.ucAccessPolicy = 1;
333 pTSInfo->field.ucAggregation = 0;
334 pTSInfo->field.ucPSB = 0;
335 pTSInfo->field.ucUP = UP;
336 pTSInfo->field.ucTSInfoAckPolicy = 0;
337 pTSInfo->field.ucSchedule = 0;
339 MakeTSEntry(*ppTS, Addr, &TSpec, NULL, 0, 0);
340 list_add_tail(&((*ppTS)->List), pAddmitList);
345 netdev_warn(ieee->dev,
346 "There is not enough dir=%d(0=up down=1) TS record to be used!",
351 static void RemoveTsEntry(struct rtllib_device *ieee,
352 struct ts_common_info *pTs, enum tr_select TxRxSelect)
354 rtllib_ts_init_del_ba(ieee, pTs, TxRxSelect);
356 if (TxRxSelect == RX_DIR) {
357 struct rx_reorder_entry *pRxReorderEntry;
358 struct rx_ts_record *pRxTS = (struct rx_ts_record *)pTs;
360 if (timer_pending(&pRxTS->rx_pkt_pending_timer))
361 del_timer_sync(&pRxTS->rx_pkt_pending_timer);
363 while (!list_empty(&pRxTS->rx_pending_pkt_list)) {
364 pRxReorderEntry = (struct rx_reorder_entry *)
365 list_entry(pRxTS->rx_pending_pkt_list.prev,
366 struct rx_reorder_entry, List);
367 netdev_dbg(ieee->dev, "%s(): Delete SeqNum %d!\n",
368 __func__, pRxReorderEntry->SeqNum);
369 list_del_init(&pRxReorderEntry->List);
372 struct rtllib_rxb *prxb = pRxReorderEntry->prxb;
376 for (i = 0; i < prxb->nr_subframes; i++)
377 dev_kfree_skb(prxb->subframes[i]);
381 list_add_tail(&pRxReorderEntry->List,
382 &ieee->RxReorder_Unused_List);
385 struct tx_ts_record *pTxTS = (struct tx_ts_record *)pTs;
387 del_timer_sync(&pTxTS->TsAddBaTimer);
391 void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr)
393 struct ts_common_info *pTS, *pTmpTS;
395 netdev_info(ieee->dev, "===========>%s, %pM\n", __func__, Addr);
397 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List) {
398 if (memcmp(pTS->Addr, Addr, 6) == 0) {
399 RemoveTsEntry(ieee, pTS, TX_DIR);
400 list_del_init(&pTS->List);
401 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
405 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List) {
406 if (memcmp(pTS->Addr, Addr, 6) == 0) {
407 netdev_info(ieee->dev,
408 "====>remove Tx_TS_admin_list\n");
409 RemoveTsEntry(ieee, pTS, TX_DIR);
410 list_del_init(&pTS->List);
411 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
415 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List) {
416 if (memcmp(pTS->Addr, Addr, 6) == 0) {
417 RemoveTsEntry(ieee, pTS, RX_DIR);
418 list_del_init(&pTS->List);
419 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
423 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List) {
424 if (memcmp(pTS->Addr, Addr, 6) == 0) {
425 RemoveTsEntry(ieee, pTS, RX_DIR);
426 list_del_init(&pTS->List);
427 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
431 EXPORT_SYMBOL(RemovePeerTS);
433 void RemoveAllTS(struct rtllib_device *ieee)
435 struct ts_common_info *pTS, *pTmpTS;
437 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List) {
438 RemoveTsEntry(ieee, pTS, TX_DIR);
439 list_del_init(&pTS->List);
440 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
443 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List) {
444 RemoveTsEntry(ieee, pTS, TX_DIR);
445 list_del_init(&pTS->List);
446 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
449 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List) {
450 RemoveTsEntry(ieee, pTS, RX_DIR);
451 list_del_init(&pTS->List);
452 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
455 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List) {
456 RemoveTsEntry(ieee, pTS, RX_DIR);
457 list_del_init(&pTS->List);
458 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
462 void TsStartAddBaProcess(struct rtllib_device *ieee, struct tx_ts_record *pTxTS)
464 if (pTxTS->bAddBaReqInProgress == false) {
465 pTxTS->bAddBaReqInProgress = true;
467 if (pTxTS->bAddBaReqDelayed) {
468 netdev_dbg(ieee->dev, "Start ADDBA after 60 sec!!\n");
469 mod_timer(&pTxTS->TsAddBaTimer, jiffies +
470 msecs_to_jiffies(TS_ADDBA_DELAY));
472 netdev_dbg(ieee->dev, "Immediately Start ADDBA\n");
473 mod_timer(&pTxTS->TsAddBaTimer, jiffies + 10);
476 netdev_dbg(ieee->dev, "BA timer is already added\n");