11n_rxreorder.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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. return;
  187. dev_dbg(reorder_cnxt->priv->adapter->dev, "info: flush data %d\n",
  188. start_win);
  189. mwifiex_11n_dispatch_pkt_until_start_win(reorder_cnxt->priv,
  190. reorder_cnxt->ptr,
  191. ((reorder_cnxt->ptr->start_win
  192. + start_win + 1) &
  193. (MAX_TID_VALUE - 1)));
  194. }
  195. /*
  196. * This function creates an entry in Rx reordering table for the
  197. * given TA/TID.
  198. *
  199. * The function also initializes the entry with sequence number, window
  200. * size as well as initializes the timer.
  201. *
  202. * If the received TA/TID pair is already present, all the packets are
  203. * dispatched and the window size is moved until the SSN.
  204. */
  205. static void
  206. mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private *priv, u8 *ta,
  207. int tid, int win_size, int seq_num)
  208. {
  209. int i;
  210. struct mwifiex_rx_reorder_tbl *rx_reor_tbl_ptr, *new_node;
  211. u16 last_seq = 0;
  212. unsigned long flags;
  213. /*
  214. * If we get a TID, ta pair which is already present dispatch all the
  215. * the packets and move the window size until the ssn
  216. */
  217. rx_reor_tbl_ptr = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta);
  218. if (rx_reor_tbl_ptr) {
  219. mwifiex_11n_dispatch_pkt_until_start_win(priv, rx_reor_tbl_ptr,
  220. seq_num);
  221. return;
  222. }
  223. /* if !rx_reor_tbl_ptr then create one */
  224. new_node = kzalloc(sizeof(struct mwifiex_rx_reorder_tbl), GFP_KERNEL);
  225. if (!new_node) {
  226. dev_err(priv->adapter->dev, "%s: failed to alloc new_node\n",
  227. __func__);
  228. return;
  229. }
  230. INIT_LIST_HEAD(&new_node->list);
  231. new_node->tid = tid;
  232. memcpy(new_node->ta, ta, ETH_ALEN);
  233. new_node->start_win = seq_num;
  234. if (mwifiex_queuing_ra_based(priv))
  235. /* TODO for adhoc */
  236. dev_dbg(priv->adapter->dev,
  237. "info: ADHOC:last_seq=%d start_win=%d\n",
  238. last_seq, new_node->start_win);
  239. else
  240. last_seq = priv->rx_seq[tid];
  241. if (last_seq >= new_node->start_win)
  242. new_node->start_win = last_seq + 1;
  243. new_node->win_size = win_size;
  244. new_node->rx_reorder_ptr = kzalloc(sizeof(void *) * win_size,
  245. GFP_KERNEL);
  246. if (!new_node->rx_reorder_ptr) {
  247. kfree((u8 *) new_node);
  248. dev_err(priv->adapter->dev,
  249. "%s: failed to alloc reorder_ptr\n", __func__);
  250. return;
  251. }
  252. new_node->timer_context.ptr = new_node;
  253. new_node->timer_context.priv = priv;
  254. init_timer(&new_node->timer_context.timer);
  255. new_node->timer_context.timer.function = mwifiex_flush_data;
  256. new_node->timer_context.timer.data =
  257. (unsigned long) &new_node->timer_context;
  258. for (i = 0; i < win_size; ++i)
  259. new_node->rx_reorder_ptr[i] = NULL;
  260. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  261. list_add_tail(&new_node->list, &priv->rx_reorder_tbl_ptr);
  262. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  263. }
  264. /*
  265. * This function prepares command for adding a BA request.
  266. *
  267. * Preparation includes -
  268. * - Setting command ID and proper size
  269. * - Setting add BA request buffer
  270. * - Ensuring correct endian-ness
  271. */
  272. int mwifiex_cmd_11n_addba_req(struct host_cmd_ds_command *cmd, void *data_buf)
  273. {
  274. struct host_cmd_ds_11n_addba_req *add_ba_req =
  275. (struct host_cmd_ds_11n_addba_req *)
  276. &cmd->params.add_ba_req;
  277. cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_REQ);
  278. cmd->size = cpu_to_le16(sizeof(*add_ba_req) + S_DS_GEN);
  279. memcpy(add_ba_req, data_buf, sizeof(*add_ba_req));
  280. return 0;
  281. }
  282. /*
  283. * This function prepares command for adding a BA response.
  284. *
  285. * Preparation includes -
  286. * - Setting command ID and proper size
  287. * - Setting add BA response buffer
  288. * - Ensuring correct endian-ness
  289. */
  290. int mwifiex_cmd_11n_addba_rsp_gen(struct mwifiex_private *priv,
  291. struct host_cmd_ds_command *cmd,
  292. struct host_cmd_ds_11n_addba_req
  293. *cmd_addba_req)
  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. u8 tid;
  299. int win_size;
  300. uint16_t block_ack_param_set;
  301. cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_RSP);
  302. cmd->size = cpu_to_le16(sizeof(*add_ba_rsp) + S_DS_GEN);
  303. memcpy(add_ba_rsp->peer_mac_addr, cmd_addba_req->peer_mac_addr,
  304. ETH_ALEN);
  305. add_ba_rsp->dialog_token = cmd_addba_req->dialog_token;
  306. add_ba_rsp->block_ack_tmo = cmd_addba_req->block_ack_tmo;
  307. add_ba_rsp->ssn = cmd_addba_req->ssn;
  308. block_ack_param_set = le16_to_cpu(cmd_addba_req->block_ack_param_set);
  309. tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK)
  310. >> BLOCKACKPARAM_TID_POS;
  311. add_ba_rsp->status_code = cpu_to_le16(ADDBA_RSP_STATUS_ACCEPT);
  312. block_ack_param_set &= ~IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK;
  313. /* We donot support AMSDU inside AMPDU, hence reset the bit */
  314. block_ack_param_set &= ~BLOCKACKPARAM_AMSDU_SUPP_MASK;
  315. block_ack_param_set |= (priv->add_ba_param.rx_win_size <<
  316. BLOCKACKPARAM_WINSIZE_POS);
  317. add_ba_rsp->block_ack_param_set = cpu_to_le16(block_ack_param_set);
  318. win_size = (le16_to_cpu(add_ba_rsp->block_ack_param_set)
  319. & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK)
  320. >> BLOCKACKPARAM_WINSIZE_POS;
  321. cmd_addba_req->block_ack_param_set = cpu_to_le16(block_ack_param_set);
  322. mwifiex_11n_create_rx_reorder_tbl(priv, cmd_addba_req->peer_mac_addr,
  323. tid, win_size, le16_to_cpu(cmd_addba_req->ssn));
  324. return 0;
  325. }
  326. /*
  327. * This function prepares command for deleting a BA request.
  328. *
  329. * Preparation includes -
  330. * - Setting command ID and proper size
  331. * - Setting del BA request buffer
  332. * - Ensuring correct endian-ness
  333. */
  334. int mwifiex_cmd_11n_delba(struct host_cmd_ds_command *cmd, void *data_buf)
  335. {
  336. struct host_cmd_ds_11n_delba *del_ba = (struct host_cmd_ds_11n_delba *)
  337. &cmd->params.del_ba;
  338. cmd->command = cpu_to_le16(HostCmd_CMD_11N_DELBA);
  339. cmd->size = cpu_to_le16(sizeof(*del_ba) + S_DS_GEN);
  340. memcpy(del_ba, data_buf, sizeof(*del_ba));
  341. return 0;
  342. }
  343. /*
  344. * This function identifies if Rx reordering is needed for a received packet.
  345. *
  346. * In case reordering is required, the function will do the reordering
  347. * before sending it to kernel.
  348. *
  349. * The Rx reorder table is checked first with the received TID/TA pair. If
  350. * not found, the received packet is dispatched immediately. But if found,
  351. * the packet is reordered and all the packets in the updated Rx reordering
  352. * table is dispatched until a hole is found.
  353. *
  354. * For sequence number less than the starting window, the packet is dropped.
  355. */
  356. int mwifiex_11n_rx_reorder_pkt(struct mwifiex_private *priv,
  357. u16 seq_num, u16 tid,
  358. u8 *ta, u8 pkt_type, void *payload)
  359. {
  360. struct mwifiex_rx_reorder_tbl *rx_reor_tbl_ptr;
  361. int start_win, end_win, win_size;
  362. u16 pkt_index;
  363. rx_reor_tbl_ptr =
  364. mwifiex_11n_get_rx_reorder_tbl((struct mwifiex_private *) priv,
  365. tid, ta);
  366. if (!rx_reor_tbl_ptr) {
  367. if (pkt_type != PKT_TYPE_BAR)
  368. mwifiex_process_rx_packet(priv->adapter, payload);
  369. return 0;
  370. }
  371. start_win = rx_reor_tbl_ptr->start_win;
  372. win_size = rx_reor_tbl_ptr->win_size;
  373. end_win = ((start_win + win_size) - 1) & (MAX_TID_VALUE - 1);
  374. del_timer(&rx_reor_tbl_ptr->timer_context.timer);
  375. mod_timer(&rx_reor_tbl_ptr->timer_context.timer, jiffies
  376. + (MIN_FLUSH_TIMER_MS * win_size * HZ) / 1000);
  377. /*
  378. * If seq_num is less then starting win then ignore and drop the
  379. * packet
  380. */
  381. if ((start_win + TWOPOW11) > (MAX_TID_VALUE - 1)) {/* Wrap */
  382. if (seq_num >= ((start_win + (TWOPOW11)) & (MAX_TID_VALUE - 1))
  383. && (seq_num < start_win))
  384. return -1;
  385. } else if ((seq_num < start_win)
  386. || (seq_num > (start_win + (TWOPOW11)))) {
  387. return -1;
  388. }
  389. /*
  390. * If this packet is a BAR we adjust seq_num as
  391. * WinStart = seq_num
  392. */
  393. if (pkt_type == PKT_TYPE_BAR)
  394. seq_num = ((seq_num + win_size) - 1) & (MAX_TID_VALUE - 1);
  395. if (((end_win < start_win)
  396. && (seq_num < (TWOPOW11 - (MAX_TID_VALUE - start_win)))
  397. && (seq_num > end_win)) || ((end_win > start_win)
  398. && ((seq_num > end_win) || (seq_num < start_win)))) {
  399. end_win = seq_num;
  400. if (((seq_num - win_size) + 1) >= 0)
  401. start_win = (end_win - win_size) + 1;
  402. else
  403. start_win = (MAX_TID_VALUE - (win_size - seq_num)) + 1;
  404. mwifiex_11n_dispatch_pkt_until_start_win(priv,
  405. rx_reor_tbl_ptr, start_win);
  406. }
  407. if (pkt_type != PKT_TYPE_BAR) {
  408. if (seq_num >= start_win)
  409. pkt_index = seq_num - start_win;
  410. else
  411. pkt_index = (seq_num+MAX_TID_VALUE) - start_win;
  412. if (rx_reor_tbl_ptr->rx_reorder_ptr[pkt_index])
  413. return -1;
  414. rx_reor_tbl_ptr->rx_reorder_ptr[pkt_index] = payload;
  415. }
  416. /*
  417. * Dispatch all packets sequentially from start_win until a
  418. * hole is found and adjust the start_win appropriately
  419. */
  420. mwifiex_11n_scan_and_dispatch(priv, rx_reor_tbl_ptr);
  421. return 0;
  422. }
  423. /*
  424. * This function deletes an entry for a given TID/TA pair.
  425. *
  426. * The TID/TA are taken from del BA event body.
  427. */
  428. void
  429. mwifiex_del_ba_tbl(struct mwifiex_private *priv, int tid, u8 *peer_mac,
  430. u8 type, int initiator)
  431. {
  432. struct mwifiex_rx_reorder_tbl *rx_reor_tbl_ptr;
  433. struct mwifiex_tx_ba_stream_tbl *ptx_tbl;
  434. u8 cleanup_rx_reorder_tbl;
  435. unsigned long flags;
  436. if (type == TYPE_DELBA_RECEIVE)
  437. cleanup_rx_reorder_tbl = (initiator) ? true : false;
  438. else
  439. cleanup_rx_reorder_tbl = (initiator) ? false : true;
  440. dev_dbg(priv->adapter->dev, "event: DELBA: %pM tid=%d, "
  441. "initiator=%d\n", peer_mac, tid, initiator);
  442. if (cleanup_rx_reorder_tbl) {
  443. rx_reor_tbl_ptr = mwifiex_11n_get_rx_reorder_tbl(priv, tid,
  444. peer_mac);
  445. if (!rx_reor_tbl_ptr) {
  446. dev_dbg(priv->adapter->dev,
  447. "event: TID, TA not found in table\n");
  448. return;
  449. }
  450. mwifiex_11n_delete_rx_reorder_tbl_entry(priv, rx_reor_tbl_ptr);
  451. } else {
  452. ptx_tbl = mwifiex_get_ba_tbl(priv, tid, peer_mac);
  453. if (!ptx_tbl) {
  454. dev_dbg(priv->adapter->dev,
  455. "event: TID, RA not found in table\n");
  456. return;
  457. }
  458. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  459. mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, ptx_tbl);
  460. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  461. }
  462. }
  463. /*
  464. * This function handles the command response of an add BA response.
  465. *
  466. * Handling includes changing the header fields into CPU format and
  467. * creating the stream, provided the add BA is accepted.
  468. */
  469. int mwifiex_ret_11n_addba_resp(struct mwifiex_private *priv,
  470. struct host_cmd_ds_command *resp)
  471. {
  472. struct host_cmd_ds_11n_addba_rsp *add_ba_rsp =
  473. (struct host_cmd_ds_11n_addba_rsp *)
  474. &resp->params.add_ba_rsp;
  475. int tid, win_size;
  476. struct mwifiex_rx_reorder_tbl *rx_reor_tbl_ptr;
  477. uint16_t block_ack_param_set;
  478. block_ack_param_set = le16_to_cpu(add_ba_rsp->block_ack_param_set);
  479. tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK)
  480. >> BLOCKACKPARAM_TID_POS;
  481. /*
  482. * Check if we had rejected the ADDBA, if yes then do not create
  483. * the stream
  484. */
  485. if (le16_to_cpu(add_ba_rsp->status_code) == BA_RESULT_SUCCESS) {
  486. win_size = (block_ack_param_set &
  487. IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK)
  488. >> BLOCKACKPARAM_WINSIZE_POS;
  489. dev_dbg(priv->adapter->dev, "cmd: ADDBA RSP: %pM"
  490. " tid=%d ssn=%d win_size=%d\n",
  491. add_ba_rsp->peer_mac_addr,
  492. tid, add_ba_rsp->ssn, win_size);
  493. } else {
  494. dev_err(priv->adapter->dev, "ADDBA RSP: failed %pM tid=%d)\n",
  495. add_ba_rsp->peer_mac_addr, tid);
  496. rx_reor_tbl_ptr = mwifiex_11n_get_rx_reorder_tbl(priv,
  497. tid, add_ba_rsp->peer_mac_addr);
  498. if (rx_reor_tbl_ptr)
  499. mwifiex_11n_delete_rx_reorder_tbl_entry(priv,
  500. rx_reor_tbl_ptr);
  501. }
  502. return 0;
  503. }
  504. /*
  505. * This function handles BA stream timeout event by preparing and sending
  506. * a command to the firmware.
  507. */
  508. void mwifiex_11n_ba_stream_timeout(struct mwifiex_private *priv,
  509. struct host_cmd_ds_11n_batimeout *event)
  510. {
  511. struct host_cmd_ds_11n_delba delba;
  512. memset(&delba, 0, sizeof(struct host_cmd_ds_11n_delba));
  513. memcpy(delba.peer_mac_addr, event->peer_mac_addr, ETH_ALEN);
  514. delba.del_ba_param_set |=
  515. cpu_to_le16((u16) event->tid << DELBA_TID_POS);
  516. delba.del_ba_param_set |= cpu_to_le16(
  517. (u16) event->origninator << DELBA_INITIATOR_POS);
  518. delba.reason_code = cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
  519. mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_DELBA, 0, 0, &delba);
  520. }
  521. /*
  522. * This function cleans up the Rx reorder table by deleting all the entries
  523. * and re-initializing.
  524. */
  525. void mwifiex_11n_cleanup_reorder_tbl(struct mwifiex_private *priv)
  526. {
  527. struct mwifiex_rx_reorder_tbl *del_tbl_ptr, *tmp_node;
  528. unsigned long flags;
  529. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  530. list_for_each_entry_safe(del_tbl_ptr, tmp_node,
  531. &priv->rx_reorder_tbl_ptr, list) {
  532. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  533. mwifiex_11n_delete_rx_reorder_tbl_entry(priv, del_tbl_ptr);
  534. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  535. }
  536. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  537. INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
  538. memset(priv->rx_seq, 0, sizeof(priv->rx_seq));
  539. }