11n_rxreorder.c 19 KB

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