11n_rxreorder.c 19 KB

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