11n_rxreorder.c 19 KB

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