11n_rxreorder.c 19 KB

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