11n_rxreorder.c 18 KB

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