rtl819x_TSProc.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. /******************************************************************************
  2. * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
  3. *
  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
  7. * more details.
  8. *
  9. * The full GNU General Public License is included in this distribution in the
  10. * file called LICENSE.
  11. *
  12. * Contact Information:
  13. * wlanfae <wlanfae@realtek.com>
  14. ******************************************************************************/
  15. #include "rtllib.h"
  16. #include <linux/etherdevice.h>
  17. #include "rtl819x_TS.h"
  18. static void TsSetupTimeOut(unsigned long data)
  19. {
  20. }
  21. static void TsInactTimeout(unsigned long data)
  22. {
  23. }
  24. static void RxPktPendingTimeout(unsigned long data)
  25. {
  26. struct rx_ts_record *pRxTs = (struct rx_ts_record *)data;
  27. struct rtllib_device *ieee = container_of(pRxTs, struct rtllib_device,
  28. RxTsRecord[pRxTs->num]);
  29. struct rx_reorder_entry *pReorderEntry = NULL;
  30. unsigned long flags = 0;
  31. u8 index = 0;
  32. bool bPktInBuf = false;
  33. spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
  34. if (pRxTs->RxTimeoutIndicateSeq != 0xffff) {
  35. while (!list_empty(&pRxTs->RxPendingPktList)) {
  36. pReorderEntry = (struct rx_reorder_entry *)
  37. list_entry(pRxTs->RxPendingPktList.prev,
  38. struct rx_reorder_entry, List);
  39. if (index == 0)
  40. pRxTs->RxIndicateSeq = pReorderEntry->SeqNum;
  41. if (SN_LESS(pReorderEntry->SeqNum,
  42. pRxTs->RxIndicateSeq) ||
  43. SN_EQUAL(pReorderEntry->SeqNum,
  44. pRxTs->RxIndicateSeq)) {
  45. list_del_init(&pReorderEntry->List);
  46. if (SN_EQUAL(pReorderEntry->SeqNum,
  47. pRxTs->RxIndicateSeq))
  48. pRxTs->RxIndicateSeq =
  49. (pRxTs->RxIndicateSeq + 1) % 4096;
  50. netdev_dbg(ieee->dev,
  51. "%s(): Indicate SeqNum: %d\n",
  52. __func__, pReorderEntry->SeqNum);
  53. ieee->stats_IndicateArray[index] =
  54. pReorderEntry->prxb;
  55. index++;
  56. list_add_tail(&pReorderEntry->List,
  57. &ieee->RxReorder_Unused_List);
  58. } else {
  59. bPktInBuf = true;
  60. break;
  61. }
  62. }
  63. }
  64. if (index > 0) {
  65. pRxTs->RxTimeoutIndicateSeq = 0xffff;
  66. if (index > REORDER_WIN_SIZE) {
  67. netdev_warn(ieee->dev,
  68. "%s(): Rx Reorder struct buffer full\n",
  69. __func__);
  70. spin_unlock_irqrestore(&(ieee->reorder_spinlock),
  71. flags);
  72. return;
  73. }
  74. rtllib_indicate_packets(ieee, ieee->stats_IndicateArray, index);
  75. bPktInBuf = false;
  76. }
  77. if (bPktInBuf && (pRxTs->RxTimeoutIndicateSeq == 0xffff)) {
  78. pRxTs->RxTimeoutIndicateSeq = pRxTs->RxIndicateSeq;
  79. mod_timer(&pRxTs->RxPktPendingTimer, jiffies +
  80. msecs_to_jiffies(ieee->pHTInfo->RxReorderPendingTime)
  81. );
  82. }
  83. spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
  84. }
  85. static void TsAddBaProcess(unsigned long data)
  86. {
  87. struct tx_ts_record *pTxTs = (struct tx_ts_record *)data;
  88. u8 num = pTxTs->num;
  89. struct rtllib_device *ieee = container_of(pTxTs, struct rtllib_device,
  90. TxTsRecord[num]);
  91. TsInitAddBA(ieee, pTxTs, BA_POLICY_IMMEDIATE, false);
  92. netdev_dbg(ieee->dev, "%s(): ADDBA Req is started\n", __func__);
  93. }
  94. static void ResetTsCommonInfo(struct ts_common_info *pTsCommonInfo)
  95. {
  96. eth_zero_addr(pTsCommonInfo->Addr);
  97. memset(&pTsCommonInfo->TSpec, 0, sizeof(union tspec_body));
  98. memset(&pTsCommonInfo->TClass, 0, sizeof(union qos_tclas)*TCLAS_NUM);
  99. pTsCommonInfo->TClasProc = 0;
  100. pTsCommonInfo->TClasNum = 0;
  101. }
  102. static void ResetTxTsEntry(struct tx_ts_record *pTS)
  103. {
  104. ResetTsCommonInfo(&pTS->TsCommonInfo);
  105. pTS->TxCurSeq = 0;
  106. pTS->bAddBaReqInProgress = false;
  107. pTS->bAddBaReqDelayed = false;
  108. pTS->bUsingBa = false;
  109. pTS->bDisable_AddBa = false;
  110. ResetBaEntry(&pTS->TxAdmittedBARecord);
  111. ResetBaEntry(&pTS->TxPendingBARecord);
  112. }
  113. static void ResetRxTsEntry(struct rx_ts_record *pTS)
  114. {
  115. ResetTsCommonInfo(&pTS->TsCommonInfo);
  116. pTS->RxIndicateSeq = 0xffff;
  117. pTS->RxTimeoutIndicateSeq = 0xffff;
  118. ResetBaEntry(&pTS->RxAdmittedBARecord);
  119. }
  120. void TSInitialize(struct rtllib_device *ieee)
  121. {
  122. struct tx_ts_record *pTxTS = ieee->TxTsRecord;
  123. struct rx_ts_record *pRxTS = ieee->RxTsRecord;
  124. struct rx_reorder_entry *pRxReorderEntry = ieee->RxReorderEntry;
  125. u8 count = 0;
  126. netdev_vdbg(ieee->dev, "%s()\n", __func__);
  127. INIT_LIST_HEAD(&ieee->Tx_TS_Admit_List);
  128. INIT_LIST_HEAD(&ieee->Tx_TS_Pending_List);
  129. INIT_LIST_HEAD(&ieee->Tx_TS_Unused_List);
  130. for (count = 0; count < TOTAL_TS_NUM; count++) {
  131. pTxTS->num = count;
  132. setup_timer(&pTxTS->TsCommonInfo.SetupTimer,
  133. TsSetupTimeOut,
  134. (unsigned long) pTxTS);
  135. setup_timer(&pTxTS->TsCommonInfo.InactTimer,
  136. TsInactTimeout,
  137. (unsigned long) pTxTS);
  138. setup_timer(&pTxTS->TsAddBaTimer,
  139. TsAddBaProcess,
  140. (unsigned long) pTxTS);
  141. setup_timer(&pTxTS->TxPendingBARecord.Timer,
  142. BaSetupTimeOut,
  143. (unsigned long) pTxTS);
  144. setup_timer(&pTxTS->TxAdmittedBARecord.Timer,
  145. TxBaInactTimeout,
  146. (unsigned long) pTxTS);
  147. ResetTxTsEntry(pTxTS);
  148. list_add_tail(&pTxTS->TsCommonInfo.List,
  149. &ieee->Tx_TS_Unused_List);
  150. pTxTS++;
  151. }
  152. INIT_LIST_HEAD(&ieee->Rx_TS_Admit_List);
  153. INIT_LIST_HEAD(&ieee->Rx_TS_Pending_List);
  154. INIT_LIST_HEAD(&ieee->Rx_TS_Unused_List);
  155. for (count = 0; count < TOTAL_TS_NUM; count++) {
  156. pRxTS->num = count;
  157. INIT_LIST_HEAD(&pRxTS->RxPendingPktList);
  158. setup_timer(&pRxTS->TsCommonInfo.SetupTimer,
  159. TsSetupTimeOut,
  160. (unsigned long) pRxTS);
  161. setup_timer(&pRxTS->TsCommonInfo.InactTimer,
  162. TsInactTimeout,
  163. (unsigned long) pRxTS);
  164. setup_timer(&pRxTS->RxAdmittedBARecord.Timer,
  165. RxBaInactTimeout,
  166. (unsigned long) pRxTS);
  167. setup_timer(&pRxTS->RxPktPendingTimer,
  168. RxPktPendingTimeout,
  169. (unsigned long) pRxTS);
  170. ResetRxTsEntry(pRxTS);
  171. list_add_tail(&pRxTS->TsCommonInfo.List,
  172. &ieee->Rx_TS_Unused_List);
  173. pRxTS++;
  174. }
  175. INIT_LIST_HEAD(&ieee->RxReorder_Unused_List);
  176. for (count = 0; count < REORDER_ENTRY_NUM; count++) {
  177. list_add_tail(&pRxReorderEntry->List,
  178. &ieee->RxReorder_Unused_List);
  179. if (count == (REORDER_ENTRY_NUM-1))
  180. break;
  181. pRxReorderEntry = &ieee->RxReorderEntry[count+1];
  182. }
  183. }
  184. static void AdmitTS(struct rtllib_device *ieee,
  185. struct ts_common_info *pTsCommonInfo, u32 InactTime)
  186. {
  187. del_timer_sync(&pTsCommonInfo->SetupTimer);
  188. del_timer_sync(&pTsCommonInfo->InactTimer);
  189. if (InactTime != 0)
  190. mod_timer(&pTsCommonInfo->InactTimer, jiffies +
  191. msecs_to_jiffies(InactTime));
  192. }
  193. static struct ts_common_info *SearchAdmitTRStream(struct rtllib_device *ieee,
  194. u8 *Addr, u8 TID,
  195. enum tr_select TxRxSelect)
  196. {
  197. u8 dir;
  198. bool search_dir[4] = {0};
  199. struct list_head *psearch_list;
  200. struct ts_common_info *pRet = NULL;
  201. if (ieee->iw_mode == IW_MODE_MASTER) {
  202. if (TxRxSelect == TX_DIR) {
  203. search_dir[DIR_DOWN] = true;
  204. search_dir[DIR_BI_DIR] = true;
  205. } else {
  206. search_dir[DIR_UP] = true;
  207. search_dir[DIR_BI_DIR] = true;
  208. }
  209. } else if (ieee->iw_mode == IW_MODE_ADHOC) {
  210. if (TxRxSelect == TX_DIR)
  211. search_dir[DIR_UP] = true;
  212. else
  213. search_dir[DIR_DOWN] = true;
  214. } else {
  215. if (TxRxSelect == TX_DIR) {
  216. search_dir[DIR_UP] = true;
  217. search_dir[DIR_BI_DIR] = true;
  218. search_dir[DIR_DIRECT] = true;
  219. } else {
  220. search_dir[DIR_DOWN] = true;
  221. search_dir[DIR_BI_DIR] = true;
  222. search_dir[DIR_DIRECT] = true;
  223. }
  224. }
  225. if (TxRxSelect == TX_DIR)
  226. psearch_list = &ieee->Tx_TS_Admit_List;
  227. else
  228. psearch_list = &ieee->Rx_TS_Admit_List;
  229. for (dir = 0; dir <= DIR_BI_DIR; dir++) {
  230. if (!search_dir[dir])
  231. continue;
  232. list_for_each_entry(pRet, psearch_list, List) {
  233. if (memcmp(pRet->Addr, Addr, 6) == 0 &&
  234. pRet->TSpec.f.TSInfo.field.ucTSID == TID &&
  235. pRet->TSpec.f.TSInfo.field.ucDirection == dir)
  236. break;
  237. }
  238. if (&pRet->List != psearch_list)
  239. break;
  240. }
  241. if (pRet && &pRet->List != psearch_list)
  242. return pRet;
  243. return NULL;
  244. }
  245. static void MakeTSEntry(struct ts_common_info *pTsCommonInfo, u8 *Addr,
  246. union tspec_body *pTSPEC, union qos_tclas *pTCLAS,
  247. u8 TCLAS_Num, u8 TCLAS_Proc)
  248. {
  249. u8 count;
  250. if (pTsCommonInfo == NULL)
  251. return;
  252. memcpy(pTsCommonInfo->Addr, Addr, 6);
  253. if (pTSPEC != NULL)
  254. memcpy((u8 *)(&(pTsCommonInfo->TSpec)), (u8 *)pTSPEC,
  255. sizeof(union tspec_body));
  256. for (count = 0; count < TCLAS_Num; count++)
  257. memcpy((u8 *)(&(pTsCommonInfo->TClass[count])),
  258. (u8 *)pTCLAS, sizeof(union qos_tclas));
  259. pTsCommonInfo->TClasProc = TCLAS_Proc;
  260. pTsCommonInfo->TClasNum = TCLAS_Num;
  261. }
  262. bool GetTs(struct rtllib_device *ieee, struct ts_common_info **ppTS,
  263. u8 *Addr, u8 TID, enum tr_select TxRxSelect, bool bAddNewTs)
  264. {
  265. u8 UP = 0;
  266. union tspec_body TSpec;
  267. union qos_tsinfo *pTSInfo = &TSpec.f.TSInfo;
  268. struct list_head *pUnusedList;
  269. struct list_head *pAddmitList;
  270. enum direction_value Dir;
  271. if (is_multicast_ether_addr(Addr)) {
  272. netdev_warn(ieee->dev, "Get TS for Broadcast or Multicast\n");
  273. return false;
  274. }
  275. if (ieee->current_network.qos_data.supported == 0) {
  276. UP = 0;
  277. } else {
  278. if (!IsACValid(TID)) {
  279. netdev_warn(ieee->dev, "%s(): TID(%d) is not valid\n",
  280. __func__, TID);
  281. return false;
  282. }
  283. switch (TID) {
  284. case 0:
  285. case 3:
  286. UP = 0;
  287. break;
  288. case 1:
  289. case 2:
  290. UP = 2;
  291. break;
  292. case 4:
  293. case 5:
  294. UP = 5;
  295. break;
  296. case 6:
  297. case 7:
  298. UP = 7;
  299. break;
  300. }
  301. }
  302. *ppTS = SearchAdmitTRStream(ieee, Addr, UP, TxRxSelect);
  303. if (*ppTS != NULL)
  304. return true;
  305. if (!bAddNewTs) {
  306. netdev_dbg(ieee->dev, "add new TS failed(tid:%d)\n", UP);
  307. return false;
  308. }
  309. pUnusedList = (TxRxSelect == TX_DIR) ?
  310. (&ieee->Tx_TS_Unused_List) :
  311. (&ieee->Rx_TS_Unused_List);
  312. pAddmitList = (TxRxSelect == TX_DIR) ?
  313. (&ieee->Tx_TS_Admit_List) :
  314. (&ieee->Rx_TS_Admit_List);
  315. Dir = (ieee->iw_mode == IW_MODE_MASTER) ?
  316. ((TxRxSelect == TX_DIR) ? DIR_DOWN : DIR_UP) :
  317. ((TxRxSelect == TX_DIR) ? DIR_UP : DIR_DOWN);
  318. if (!list_empty(pUnusedList)) {
  319. (*ppTS) = list_entry(pUnusedList->next,
  320. struct ts_common_info, List);
  321. list_del_init(&(*ppTS)->List);
  322. if (TxRxSelect == TX_DIR) {
  323. struct tx_ts_record *tmp =
  324. container_of(*ppTS,
  325. struct tx_ts_record,
  326. TsCommonInfo);
  327. ResetTxTsEntry(tmp);
  328. } else {
  329. struct rx_ts_record *tmp =
  330. container_of(*ppTS,
  331. struct rx_ts_record,
  332. TsCommonInfo);
  333. ResetRxTsEntry(tmp);
  334. }
  335. netdev_dbg(ieee->dev,
  336. "to init current TS, UP:%d, Dir:%d, addr: %pM ppTs=%p\n",
  337. UP, Dir, Addr, *ppTS);
  338. pTSInfo->field.ucTrafficType = 0;
  339. pTSInfo->field.ucTSID = UP;
  340. pTSInfo->field.ucDirection = Dir;
  341. pTSInfo->field.ucAccessPolicy = 1;
  342. pTSInfo->field.ucAggregation = 0;
  343. pTSInfo->field.ucPSB = 0;
  344. pTSInfo->field.ucUP = UP;
  345. pTSInfo->field.ucTSInfoAckPolicy = 0;
  346. pTSInfo->field.ucSchedule = 0;
  347. MakeTSEntry(*ppTS, Addr, &TSpec, NULL, 0, 0);
  348. AdmitTS(ieee, *ppTS, 0);
  349. list_add_tail(&((*ppTS)->List), pAddmitList);
  350. return true;
  351. }
  352. netdev_warn(ieee->dev,
  353. "There is not enough dir=%d(0=up down=1) TS record to be used!",
  354. Dir);
  355. return false;
  356. }
  357. static void RemoveTsEntry(struct rtllib_device *ieee,
  358. struct ts_common_info *pTs, enum tr_select TxRxSelect)
  359. {
  360. del_timer_sync(&pTs->SetupTimer);
  361. del_timer_sync(&pTs->InactTimer);
  362. TsInitDelBA(ieee, pTs, TxRxSelect);
  363. if (TxRxSelect == RX_DIR) {
  364. struct rx_reorder_entry *pRxReorderEntry;
  365. struct rx_ts_record *pRxTS = (struct rx_ts_record *)pTs;
  366. if (timer_pending(&pRxTS->RxPktPendingTimer))
  367. del_timer_sync(&pRxTS->RxPktPendingTimer);
  368. while (!list_empty(&pRxTS->RxPendingPktList)) {
  369. pRxReorderEntry = (struct rx_reorder_entry *)
  370. list_entry(pRxTS->RxPendingPktList.prev,
  371. struct rx_reorder_entry, List);
  372. netdev_dbg(ieee->dev, "%s(): Delete SeqNum %d!\n",
  373. __func__, pRxReorderEntry->SeqNum);
  374. list_del_init(&pRxReorderEntry->List);
  375. {
  376. int i = 0;
  377. struct rtllib_rxb *prxb = pRxReorderEntry->prxb;
  378. if (unlikely(!prxb))
  379. return;
  380. for (i = 0; i < prxb->nr_subframes; i++)
  381. dev_kfree_skb(prxb->subframes[i]);
  382. kfree(prxb);
  383. prxb = NULL;
  384. }
  385. list_add_tail(&pRxReorderEntry->List,
  386. &ieee->RxReorder_Unused_List);
  387. }
  388. } else {
  389. struct tx_ts_record *pTxTS = (struct tx_ts_record *)pTs;
  390. del_timer_sync(&pTxTS->TsAddBaTimer);
  391. }
  392. }
  393. void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr)
  394. {
  395. struct ts_common_info *pTS, *pTmpTS;
  396. netdev_info(ieee->dev, "===========>RemovePeerTS, %pM\n", 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);
  402. }
  403. }
  404. list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List) {
  405. if (memcmp(pTS->Addr, Addr, 6) == 0) {
  406. netdev_info(ieee->dev,
  407. "====>remove Tx_TS_admin_list\n");
  408. RemoveTsEntry(ieee, pTS, TX_DIR);
  409. list_del_init(&pTS->List);
  410. list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
  411. }
  412. }
  413. list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List) {
  414. if (memcmp(pTS->Addr, Addr, 6) == 0) {
  415. RemoveTsEntry(ieee, pTS, RX_DIR);
  416. list_del_init(&pTS->List);
  417. list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
  418. }
  419. }
  420. list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List) {
  421. if (memcmp(pTS->Addr, Addr, 6) == 0) {
  422. RemoveTsEntry(ieee, pTS, RX_DIR);
  423. list_del_init(&pTS->List);
  424. list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
  425. }
  426. }
  427. }
  428. EXPORT_SYMBOL(RemovePeerTS);
  429. void RemoveAllTS(struct rtllib_device *ieee)
  430. {
  431. struct ts_common_info *pTS, *pTmpTS;
  432. list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List) {
  433. RemoveTsEntry(ieee, pTS, TX_DIR);
  434. list_del_init(&pTS->List);
  435. list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
  436. }
  437. list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_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);
  441. }
  442. list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List) {
  443. RemoveTsEntry(ieee, pTS, RX_DIR);
  444. list_del_init(&pTS->List);
  445. list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
  446. }
  447. list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List) {
  448. RemoveTsEntry(ieee, pTS, RX_DIR);
  449. list_del_init(&pTS->List);
  450. list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
  451. }
  452. }
  453. void TsStartAddBaProcess(struct rtllib_device *ieee, struct tx_ts_record *pTxTS)
  454. {
  455. if (pTxTS->bAddBaReqInProgress == false) {
  456. pTxTS->bAddBaReqInProgress = true;
  457. if (pTxTS->bAddBaReqDelayed) {
  458. netdev_dbg(ieee->dev, "Start ADDBA after 60 sec!!\n");
  459. mod_timer(&pTxTS->TsAddBaTimer, jiffies +
  460. msecs_to_jiffies(TS_ADDBA_DELAY));
  461. } else {
  462. netdev_dbg(ieee->dev, "Immediately Start ADDBA\n");
  463. mod_timer(&pTxTS->TsAddBaTimer, jiffies+10);
  464. }
  465. } else
  466. netdev_dbg(ieee->dev, "BA timer is already added\n");
  467. }