11n_rxreorder.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. /*
  2. * Marvell Wireless LAN device driver: 802.11n RX Re-ordering
  3. *
  4. * Copyright (C) 2011, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include "decl.h"
  20. #include "ioctl.h"
  21. #include "util.h"
  22. #include "fw.h"
  23. #include "main.h"
  24. #include "wmm.h"
  25. #include "11n.h"
  26. #include "11n_rxreorder.h"
  27. /*
  28. * This function dispatches all packets in the Rx reorder table until the
  29. * start window.
  30. *
  31. * There could be holes in the buffer, which are skipped by the function.
  32. * Since the buffer is linear, the function uses rotation to simulate
  33. * circular buffer.
  34. */
  35. static void
  36. mwifiex_11n_dispatch_pkt(struct mwifiex_private *priv,
  37. struct mwifiex_rx_reorder_tbl *tbl, int start_win)
  38. {
  39. int pkt_to_send, i;
  40. void *rx_tmp_ptr;
  41. unsigned long flags;
  42. pkt_to_send = (start_win > tbl->start_win) ?
  43. min((start_win - tbl->start_win), tbl->win_size) :
  44. tbl->win_size;
  45. for (i = 0; i < pkt_to_send; ++i) {
  46. spin_lock_irqsave(&priv->rx_pkt_lock, flags);
  47. rx_tmp_ptr = NULL;
  48. if (tbl->rx_reorder_ptr[i]) {
  49. rx_tmp_ptr = tbl->rx_reorder_ptr[i];
  50. tbl->rx_reorder_ptr[i] = NULL;
  51. }
  52. spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
  53. if (rx_tmp_ptr)
  54. mwifiex_process_rx_packet(priv->adapter, rx_tmp_ptr);
  55. }
  56. spin_lock_irqsave(&priv->rx_pkt_lock, flags);
  57. /*
  58. * We don't have a circular buffer, hence use rotation to simulate
  59. * circular buffer
  60. */
  61. for (i = 0; i < tbl->win_size - pkt_to_send; ++i) {
  62. tbl->rx_reorder_ptr[i] = tbl->rx_reorder_ptr[pkt_to_send + i];
  63. tbl->rx_reorder_ptr[pkt_to_send + i] = NULL;
  64. }
  65. tbl->start_win = start_win;
  66. spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
  67. }
  68. /*
  69. * This function dispatches all packets in the Rx reorder table until
  70. * a hole is found.
  71. *
  72. * The start window is adjusted automatically when a hole is located.
  73. * Since the buffer is linear, the function uses rotation to simulate
  74. * circular buffer.
  75. */
  76. static void
  77. mwifiex_11n_scan_and_dispatch(struct mwifiex_private *priv,
  78. struct mwifiex_rx_reorder_tbl *tbl)
  79. {
  80. int i, j, xchg;
  81. void *rx_tmp_ptr;
  82. unsigned long flags;
  83. for (i = 0; i < tbl->win_size; ++i) {
  84. spin_lock_irqsave(&priv->rx_pkt_lock, flags);
  85. if (!tbl->rx_reorder_ptr[i]) {
  86. spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
  87. break;
  88. }
  89. rx_tmp_ptr = tbl->rx_reorder_ptr[i];
  90. tbl->rx_reorder_ptr[i] = NULL;
  91. spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
  92. mwifiex_process_rx_packet(priv->adapter, rx_tmp_ptr);
  93. }
  94. spin_lock_irqsave(&priv->rx_pkt_lock, flags);
  95. /*
  96. * We don't have a circular buffer, hence use rotation to simulate
  97. * circular buffer
  98. */
  99. if (i > 0) {
  100. xchg = tbl->win_size - i;
  101. for (j = 0; j < xchg; ++j) {
  102. tbl->rx_reorder_ptr[j] = tbl->rx_reorder_ptr[i + j];
  103. tbl->rx_reorder_ptr[i + j] = NULL;
  104. }
  105. }
  106. tbl->start_win = (tbl->start_win + i) & (MAX_TID_VALUE - 1);
  107. spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
  108. }
  109. /*
  110. * This function deletes the Rx reorder table and frees the memory.
  111. *
  112. * The function stops the associated timer and dispatches all the
  113. * pending packets in the Rx reorder table before deletion.
  114. */
  115. static void
  116. mwifiex_del_rx_reorder_entry(struct mwifiex_private *priv,
  117. struct mwifiex_rx_reorder_tbl *tbl)
  118. {
  119. unsigned long flags;
  120. if (!tbl)
  121. return;
  122. mwifiex_11n_dispatch_pkt(priv, tbl, (tbl->start_win + tbl->win_size) &
  123. (MAX_TID_VALUE - 1));
  124. del_timer(&tbl->timer_context.timer);
  125. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  126. list_del(&tbl->list);
  127. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  128. kfree(tbl->rx_reorder_ptr);
  129. kfree(tbl);
  130. }
  131. /*
  132. * This function returns the pointer to an entry in Rx reordering
  133. * table which matches the given TA/TID pair.
  134. */
  135. static struct mwifiex_rx_reorder_tbl *
  136. mwifiex_11n_get_rx_reorder_tbl(struct mwifiex_private *priv, int tid, u8 *ta)
  137. {
  138. struct mwifiex_rx_reorder_tbl *tbl;
  139. unsigned long flags;
  140. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  141. list_for_each_entry(tbl, &priv->rx_reorder_tbl_ptr, list) {
  142. if (!memcmp(tbl->ta, ta, ETH_ALEN) && tbl->tid == tid) {
  143. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock,
  144. flags);
  145. return tbl;
  146. }
  147. }
  148. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  149. return NULL;
  150. }
  151. /*
  152. * This function finds the last sequence number used in the packets
  153. * buffered in Rx reordering table.
  154. */
  155. static int
  156. mwifiex_11n_find_last_seq_num(struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr)
  157. {
  158. int i;
  159. for (i = (rx_reorder_tbl_ptr->win_size - 1); i >= 0; --i)
  160. if (rx_reorder_tbl_ptr->rx_reorder_ptr[i])
  161. return i;
  162. return -1;
  163. }
  164. /*
  165. * This function flushes all the packets in Rx reordering table.
  166. *
  167. * The function checks if any packets are currently buffered in the
  168. * table or not. In case there are packets available, it dispatches
  169. * them and then dumps the Rx reordering table.
  170. */
  171. static void
  172. mwifiex_flush_data(unsigned long context)
  173. {
  174. struct reorder_tmr_cnxt *ctx =
  175. (struct reorder_tmr_cnxt *) context;
  176. int start_win;
  177. start_win = mwifiex_11n_find_last_seq_num(ctx->ptr);
  178. if (start_win < 0)
  179. return;
  180. dev_dbg(ctx->priv->adapter->dev, "info: flush data %d\n", start_win);
  181. mwifiex_11n_dispatch_pkt(ctx->priv, ctx->ptr,
  182. (ctx->ptr->start_win + start_win + 1) &
  183. (MAX_TID_VALUE - 1));
  184. }
  185. /*
  186. * This function creates an entry in Rx reordering table for the
  187. * given TA/TID.
  188. *
  189. * The function also initializes the entry with sequence number, window
  190. * size as well as initializes the timer.
  191. *
  192. * If the received TA/TID pair is already present, all the packets are
  193. * dispatched and the window size is moved until the SSN.
  194. */
  195. static void
  196. mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private *priv, u8 *ta,
  197. int tid, int win_size, int seq_num)
  198. {
  199. int i;
  200. struct mwifiex_rx_reorder_tbl *tbl, *new_node;
  201. u16 last_seq = 0;
  202. unsigned long flags;
  203. /*
  204. * If we get a TID, ta pair which is already present dispatch all the
  205. * the packets and move the window size until the ssn
  206. */
  207. tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta);
  208. if (tbl) {
  209. mwifiex_11n_dispatch_pkt(priv, tbl, seq_num);
  210. return;
  211. }
  212. /* if !tbl then create one */
  213. new_node = kzalloc(sizeof(struct mwifiex_rx_reorder_tbl), GFP_KERNEL);
  214. if (!new_node) {
  215. dev_err(priv->adapter->dev, "%s: failed to alloc new_node\n",
  216. __func__);
  217. return;
  218. }
  219. INIT_LIST_HEAD(&new_node->list);
  220. new_node->tid = tid;
  221. memcpy(new_node->ta, ta, ETH_ALEN);
  222. new_node->start_win = seq_num;
  223. if (mwifiex_queuing_ra_based(priv))
  224. /* TODO for adhoc */
  225. dev_dbg(priv->adapter->dev,
  226. "info: ADHOC:last_seq=%d start_win=%d\n",
  227. last_seq, new_node->start_win);
  228. else
  229. last_seq = priv->rx_seq[tid];
  230. if (last_seq >= new_node->start_win)
  231. new_node->start_win = last_seq + 1;
  232. new_node->win_size = win_size;
  233. new_node->rx_reorder_ptr = kzalloc(sizeof(void *) * win_size,
  234. GFP_KERNEL);
  235. if (!new_node->rx_reorder_ptr) {
  236. kfree((u8 *) new_node);
  237. dev_err(priv->adapter->dev,
  238. "%s: failed to alloc reorder_ptr\n", __func__);
  239. return;
  240. }
  241. new_node->timer_context.ptr = new_node;
  242. new_node->timer_context.priv = priv;
  243. init_timer(&new_node->timer_context.timer);
  244. new_node->timer_context.timer.function = mwifiex_flush_data;
  245. new_node->timer_context.timer.data =
  246. (unsigned long) &new_node->timer_context;
  247. for (i = 0; i < win_size; ++i)
  248. new_node->rx_reorder_ptr[i] = NULL;
  249. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  250. list_add_tail(&new_node->list, &priv->rx_reorder_tbl_ptr);
  251. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  252. }
  253. /*
  254. * This function prepares command for adding a BA request.
  255. *
  256. * Preparation includes -
  257. * - Setting command ID and proper size
  258. * - Setting add BA request buffer
  259. * - Ensuring correct endian-ness
  260. */
  261. int mwifiex_cmd_11n_addba_req(struct host_cmd_ds_command *cmd, void *data_buf)
  262. {
  263. struct host_cmd_ds_11n_addba_req *add_ba_req =
  264. (struct host_cmd_ds_11n_addba_req *)
  265. &cmd->params.add_ba_req;
  266. cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_REQ);
  267. cmd->size = cpu_to_le16(sizeof(*add_ba_req) + S_DS_GEN);
  268. memcpy(add_ba_req, data_buf, sizeof(*add_ba_req));
  269. return 0;
  270. }
  271. /*
  272. * This function prepares command for adding a BA response.
  273. *
  274. * Preparation includes -
  275. * - Setting command ID and proper size
  276. * - Setting add BA response buffer
  277. * - Ensuring correct endian-ness
  278. */
  279. int mwifiex_cmd_11n_addba_rsp_gen(struct mwifiex_private *priv,
  280. struct host_cmd_ds_command *cmd,
  281. struct host_cmd_ds_11n_addba_req
  282. *cmd_addba_req)
  283. {
  284. struct host_cmd_ds_11n_addba_rsp *add_ba_rsp =
  285. (struct host_cmd_ds_11n_addba_rsp *)
  286. &cmd->params.add_ba_rsp;
  287. u8 tid;
  288. int win_size;
  289. uint16_t block_ack_param_set;
  290. cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_RSP);
  291. cmd->size = cpu_to_le16(sizeof(*add_ba_rsp) + S_DS_GEN);
  292. memcpy(add_ba_rsp->peer_mac_addr, cmd_addba_req->peer_mac_addr,
  293. ETH_ALEN);
  294. add_ba_rsp->dialog_token = cmd_addba_req->dialog_token;
  295. add_ba_rsp->block_ack_tmo = cmd_addba_req->block_ack_tmo;
  296. add_ba_rsp->ssn = cmd_addba_req->ssn;
  297. block_ack_param_set = le16_to_cpu(cmd_addba_req->block_ack_param_set);
  298. tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK)
  299. >> BLOCKACKPARAM_TID_POS;
  300. add_ba_rsp->status_code = cpu_to_le16(ADDBA_RSP_STATUS_ACCEPT);
  301. block_ack_param_set &= ~IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK;
  302. /* We donot support AMSDU inside AMPDU, hence reset the bit */
  303. block_ack_param_set &= ~BLOCKACKPARAM_AMSDU_SUPP_MASK;
  304. block_ack_param_set |= (priv->add_ba_param.rx_win_size <<
  305. BLOCKACKPARAM_WINSIZE_POS);
  306. add_ba_rsp->block_ack_param_set = cpu_to_le16(block_ack_param_set);
  307. win_size = (le16_to_cpu(add_ba_rsp->block_ack_param_set)
  308. & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK)
  309. >> BLOCKACKPARAM_WINSIZE_POS;
  310. cmd_addba_req->block_ack_param_set = cpu_to_le16(block_ack_param_set);
  311. mwifiex_11n_create_rx_reorder_tbl(priv, cmd_addba_req->peer_mac_addr,
  312. tid, win_size,
  313. le16_to_cpu(cmd_addba_req->ssn));
  314. return 0;
  315. }
  316. /*
  317. * This function prepares command for deleting a BA request.
  318. *
  319. * Preparation includes -
  320. * - Setting command ID and proper size
  321. * - Setting del BA request buffer
  322. * - Ensuring correct endian-ness
  323. */
  324. int mwifiex_cmd_11n_delba(struct host_cmd_ds_command *cmd, void *data_buf)
  325. {
  326. struct host_cmd_ds_11n_delba *del_ba = (struct host_cmd_ds_11n_delba *)
  327. &cmd->params.del_ba;
  328. cmd->command = cpu_to_le16(HostCmd_CMD_11N_DELBA);
  329. cmd->size = cpu_to_le16(sizeof(*del_ba) + S_DS_GEN);
  330. memcpy(del_ba, data_buf, sizeof(*del_ba));
  331. return 0;
  332. }
  333. /*
  334. * This function identifies if Rx reordering is needed for a received packet.
  335. *
  336. * In case reordering is required, the function will do the reordering
  337. * before sending it to kernel.
  338. *
  339. * The Rx reorder table is checked first with the received TID/TA pair. If
  340. * not found, the received packet is dispatched immediately. But if found,
  341. * the packet is reordered and all the packets in the updated Rx reordering
  342. * table is dispatched until a hole is found.
  343. *
  344. * For sequence number less than the starting window, the packet is dropped.
  345. */
  346. int mwifiex_11n_rx_reorder_pkt(struct mwifiex_private *priv,
  347. u16 seq_num, u16 tid,
  348. u8 *ta, u8 pkt_type, void *payload)
  349. {
  350. struct mwifiex_rx_reorder_tbl *tbl;
  351. int start_win, end_win, win_size;
  352. u16 pkt_index;
  353. tbl = mwifiex_11n_get_rx_reorder_tbl((struct mwifiex_private *) priv,
  354. tid, ta);
  355. if (!tbl) {
  356. if (pkt_type != PKT_TYPE_BAR)
  357. mwifiex_process_rx_packet(priv->adapter, payload);
  358. return 0;
  359. }
  360. start_win = tbl->start_win;
  361. win_size = tbl->win_size;
  362. end_win = ((start_win + win_size) - 1) & (MAX_TID_VALUE - 1);
  363. del_timer(&tbl->timer_context.timer);
  364. mod_timer(&tbl->timer_context.timer,
  365. jiffies + (MIN_FLUSH_TIMER_MS * win_size * HZ) / 1000);
  366. /*
  367. * If seq_num is less then starting win then ignore and drop the
  368. * packet
  369. */
  370. if ((start_win + TWOPOW11) > (MAX_TID_VALUE - 1)) {/* Wrap */
  371. if (seq_num >= ((start_win + TWOPOW11) &
  372. (MAX_TID_VALUE - 1)) && (seq_num < start_win))
  373. return -1;
  374. } else if ((seq_num < start_win) ||
  375. (seq_num > (start_win + TWOPOW11))) {
  376. return -1;
  377. }
  378. /*
  379. * If this packet is a BAR we adjust seq_num as
  380. * WinStart = seq_num
  381. */
  382. if (pkt_type == PKT_TYPE_BAR)
  383. seq_num = ((seq_num + win_size) - 1) & (MAX_TID_VALUE - 1);
  384. if (((end_win < start_win) &&
  385. (seq_num < (TWOPOW11 - (MAX_TID_VALUE - start_win))) &&
  386. (seq_num > end_win)) ||
  387. ((end_win > start_win) && ((seq_num > end_win) ||
  388. (seq_num < start_win)))) {
  389. end_win = seq_num;
  390. if (((seq_num - win_size) + 1) >= 0)
  391. start_win = (end_win - win_size) + 1;
  392. else
  393. start_win = (MAX_TID_VALUE - (win_size - seq_num)) + 1;
  394. mwifiex_11n_dispatch_pkt(priv, tbl, start_win);
  395. }
  396. if (pkt_type != PKT_TYPE_BAR) {
  397. if (seq_num >= start_win)
  398. pkt_index = seq_num - start_win;
  399. else
  400. pkt_index = (seq_num+MAX_TID_VALUE) - start_win;
  401. if (tbl->rx_reorder_ptr[pkt_index])
  402. return -1;
  403. tbl->rx_reorder_ptr[pkt_index] = payload;
  404. }
  405. /*
  406. * Dispatch all packets sequentially from start_win until a
  407. * hole is found and adjust the start_win appropriately
  408. */
  409. mwifiex_11n_scan_and_dispatch(priv, tbl);
  410. return 0;
  411. }
  412. /*
  413. * This function deletes an entry for a given TID/TA pair.
  414. *
  415. * The TID/TA are taken from del BA event body.
  416. */
  417. void
  418. mwifiex_del_ba_tbl(struct mwifiex_private *priv, int tid, u8 *peer_mac,
  419. u8 type, int initiator)
  420. {
  421. struct mwifiex_rx_reorder_tbl *tbl;
  422. struct mwifiex_tx_ba_stream_tbl *ptx_tbl;
  423. u8 cleanup_rx_reorder_tbl;
  424. unsigned long flags;
  425. if (type == TYPE_DELBA_RECEIVE)
  426. cleanup_rx_reorder_tbl = (initiator) ? true : false;
  427. else
  428. cleanup_rx_reorder_tbl = (initiator) ? false : true;
  429. dev_dbg(priv->adapter->dev, "event: DELBA: %pM tid=%d initiator=%d\n",
  430. peer_mac, tid, initiator);
  431. if (cleanup_rx_reorder_tbl) {
  432. tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid,
  433. peer_mac);
  434. if (!tbl) {
  435. dev_dbg(priv->adapter->dev,
  436. "event: TID, TA not found in table\n");
  437. return;
  438. }
  439. mwifiex_del_rx_reorder_entry(priv, tbl);
  440. } else {
  441. ptx_tbl = mwifiex_get_ba_tbl(priv, tid, peer_mac);
  442. if (!ptx_tbl) {
  443. dev_dbg(priv->adapter->dev,
  444. "event: TID, RA not found in table\n");
  445. return;
  446. }
  447. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  448. mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, ptx_tbl);
  449. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  450. }
  451. }
  452. /*
  453. * This function handles the command response of an add BA response.
  454. *
  455. * Handling includes changing the header fields into CPU format and
  456. * creating the stream, provided the add BA is accepted.
  457. */
  458. int mwifiex_ret_11n_addba_resp(struct mwifiex_private *priv,
  459. struct host_cmd_ds_command *resp)
  460. {
  461. struct host_cmd_ds_11n_addba_rsp *add_ba_rsp =
  462. (struct host_cmd_ds_11n_addba_rsp *)
  463. &resp->params.add_ba_rsp;
  464. int tid, win_size;
  465. struct mwifiex_rx_reorder_tbl *tbl;
  466. uint16_t block_ack_param_set;
  467. block_ack_param_set = le16_to_cpu(add_ba_rsp->block_ack_param_set);
  468. tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK)
  469. >> BLOCKACKPARAM_TID_POS;
  470. /*
  471. * Check if we had rejected the ADDBA, if yes then do not create
  472. * the stream
  473. */
  474. if (le16_to_cpu(add_ba_rsp->status_code) == BA_RESULT_SUCCESS) {
  475. win_size = (block_ack_param_set &
  476. IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK)
  477. >> BLOCKACKPARAM_WINSIZE_POS;
  478. dev_dbg(priv->adapter->dev,
  479. "cmd: ADDBA RSP: %pM tid=%d ssn=%d win_size=%d\n",
  480. add_ba_rsp->peer_mac_addr, tid,
  481. add_ba_rsp->ssn, win_size);
  482. } else {
  483. dev_err(priv->adapter->dev, "ADDBA RSP: failed %pM tid=%d)\n",
  484. add_ba_rsp->peer_mac_addr, tid);
  485. tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid,
  486. add_ba_rsp->peer_mac_addr);
  487. if (tbl)
  488. mwifiex_del_rx_reorder_entry(priv, tbl);
  489. }
  490. return 0;
  491. }
  492. /*
  493. * This function handles BA stream timeout event by preparing and sending
  494. * a command to the firmware.
  495. */
  496. void mwifiex_11n_ba_stream_timeout(struct mwifiex_private *priv,
  497. struct host_cmd_ds_11n_batimeout *event)
  498. {
  499. struct host_cmd_ds_11n_delba delba;
  500. memset(&delba, 0, sizeof(struct host_cmd_ds_11n_delba));
  501. memcpy(delba.peer_mac_addr, event->peer_mac_addr, ETH_ALEN);
  502. delba.del_ba_param_set |=
  503. cpu_to_le16((u16) event->tid << DELBA_TID_POS);
  504. delba.del_ba_param_set |= cpu_to_le16(
  505. (u16) event->origninator << DELBA_INITIATOR_POS);
  506. delba.reason_code = cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
  507. mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_DELBA, 0, 0, &delba);
  508. }
  509. /*
  510. * This function cleans up the Rx reorder table by deleting all the entries
  511. * and re-initializing.
  512. */
  513. void mwifiex_11n_cleanup_reorder_tbl(struct mwifiex_private *priv)
  514. {
  515. struct mwifiex_rx_reorder_tbl *del_tbl_ptr, *tmp_node;
  516. unsigned long flags;
  517. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  518. list_for_each_entry_safe(del_tbl_ptr, tmp_node,
  519. &priv->rx_reorder_tbl_ptr, list) {
  520. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  521. mwifiex_del_rx_reorder_entry(priv, del_tbl_ptr);
  522. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  523. }
  524. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  525. INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
  526. memset(priv->rx_seq, 0, sizeof(priv->rx_seq));
  527. }