11n_rxreorder.c 23 KB

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