11n_rxreorder.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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. /* 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. start_win = (tbl->start_win + tbl->win_size) & (MAX_TID_VALUE - 1);
  164. mwifiex_11n_dispatch_pkt_until_start_win(priv, tbl, start_win);
  165. del_timer_sync(&tbl->timer_context.timer);
  166. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  167. list_del(&tbl->list);
  168. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  169. kfree(tbl->rx_reorder_ptr);
  170. kfree(tbl);
  171. }
  172. /*
  173. * This function returns the pointer to an entry in Rx reordering
  174. * table which matches the given TA/TID pair.
  175. */
  176. struct mwifiex_rx_reorder_tbl *
  177. mwifiex_11n_get_rx_reorder_tbl(struct mwifiex_private *priv, int tid, u8 *ta)
  178. {
  179. struct mwifiex_rx_reorder_tbl *tbl;
  180. unsigned long flags;
  181. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  182. list_for_each_entry(tbl, &priv->rx_reorder_tbl_ptr, list) {
  183. if (!memcmp(tbl->ta, ta, ETH_ALEN) && tbl->tid == tid) {
  184. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock,
  185. flags);
  186. return tbl;
  187. }
  188. }
  189. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  190. return NULL;
  191. }
  192. /* This function retrieves the pointer to an entry in Rx reordering
  193. * table which matches the given TA and deletes it.
  194. */
  195. void mwifiex_11n_del_rx_reorder_tbl_by_ta(struct mwifiex_private *priv, u8 *ta)
  196. {
  197. struct mwifiex_rx_reorder_tbl *tbl, *tmp;
  198. unsigned long flags;
  199. if (!ta)
  200. return;
  201. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  202. list_for_each_entry_safe(tbl, tmp, &priv->rx_reorder_tbl_ptr, list) {
  203. if (!memcmp(tbl->ta, ta, ETH_ALEN)) {
  204. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock,
  205. flags);
  206. mwifiex_del_rx_reorder_entry(priv, tbl);
  207. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  208. }
  209. }
  210. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  211. return;
  212. }
  213. /*
  214. * This function finds the last sequence number used in the packets
  215. * buffered in Rx reordering table.
  216. */
  217. static int
  218. mwifiex_11n_find_last_seq_num(struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr)
  219. {
  220. int i;
  221. for (i = (rx_reorder_tbl_ptr->win_size - 1); i >= 0; --i)
  222. if (rx_reorder_tbl_ptr->rx_reorder_ptr[i])
  223. return i;
  224. return -1;
  225. }
  226. /*
  227. * This function flushes all the packets in Rx reordering table.
  228. *
  229. * The function checks if any packets are currently buffered in the
  230. * table or not. In case there are packets available, it dispatches
  231. * them and then dumps the Rx reordering table.
  232. */
  233. static void
  234. mwifiex_flush_data(unsigned long context)
  235. {
  236. struct reorder_tmr_cnxt *ctx =
  237. (struct reorder_tmr_cnxt *) context;
  238. int start_win, seq_num;
  239. seq_num = mwifiex_11n_find_last_seq_num(ctx->ptr);
  240. if (seq_num < 0)
  241. return;
  242. dev_dbg(ctx->priv->adapter->dev, "info: flush data %d\n", seq_num);
  243. start_win = (ctx->ptr->start_win + seq_num + 1) & (MAX_TID_VALUE - 1);
  244. mwifiex_11n_dispatch_pkt_until_start_win(ctx->priv, ctx->ptr,
  245. start_win);
  246. }
  247. /*
  248. * This function creates an entry in Rx reordering table for the
  249. * given TA/TID.
  250. *
  251. * The function also initializes the entry with sequence number, window
  252. * size as well as initializes the timer.
  253. *
  254. * If the received TA/TID pair is already present, all the packets are
  255. * dispatched and the window size is moved until the SSN.
  256. */
  257. static void
  258. mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private *priv, u8 *ta,
  259. int tid, int win_size, int seq_num)
  260. {
  261. int i;
  262. struct mwifiex_rx_reorder_tbl *tbl, *new_node;
  263. u16 last_seq = 0;
  264. unsigned long flags;
  265. struct mwifiex_sta_node *node;
  266. /*
  267. * If we get a TID, ta pair which is already present dispatch all the
  268. * the packets and move the window size until the ssn
  269. */
  270. tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta);
  271. if (tbl) {
  272. mwifiex_11n_dispatch_pkt_until_start_win(priv, tbl, seq_num);
  273. return;
  274. }
  275. /* if !tbl then create one */
  276. new_node = kzalloc(sizeof(struct mwifiex_rx_reorder_tbl), GFP_KERNEL);
  277. if (!new_node)
  278. return;
  279. INIT_LIST_HEAD(&new_node->list);
  280. new_node->tid = tid;
  281. memcpy(new_node->ta, ta, ETH_ALEN);
  282. new_node->start_win = seq_num;
  283. new_node->init_win = seq_num;
  284. new_node->flags = 0;
  285. if (mwifiex_queuing_ra_based(priv)) {
  286. dev_dbg(priv->adapter->dev,
  287. "info: AP/ADHOC:last_seq=%d start_win=%d\n",
  288. last_seq, new_node->start_win);
  289. if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) {
  290. node = mwifiex_get_sta_entry(priv, ta);
  291. if (node)
  292. last_seq = node->rx_seq[tid];
  293. }
  294. } else {
  295. node = mwifiex_get_sta_entry(priv, ta);
  296. if (node)
  297. last_seq = node->rx_seq[tid];
  298. else
  299. last_seq = priv->rx_seq[tid];
  300. }
  301. if (last_seq != MWIFIEX_DEF_11N_RX_SEQ_NUM &&
  302. last_seq >= new_node->start_win) {
  303. new_node->start_win = last_seq + 1;
  304. new_node->flags |= RXREOR_INIT_WINDOW_SHIFT;
  305. }
  306. new_node->win_size = win_size;
  307. new_node->rx_reorder_ptr = kzalloc(sizeof(void *) * win_size,
  308. GFP_KERNEL);
  309. if (!new_node->rx_reorder_ptr) {
  310. kfree((u8 *) new_node);
  311. dev_err(priv->adapter->dev,
  312. "%s: failed to alloc reorder_ptr\n", __func__);
  313. return;
  314. }
  315. new_node->timer_context.ptr = new_node;
  316. new_node->timer_context.priv = priv;
  317. init_timer(&new_node->timer_context.timer);
  318. new_node->timer_context.timer.function = mwifiex_flush_data;
  319. new_node->timer_context.timer.data =
  320. (unsigned long) &new_node->timer_context;
  321. for (i = 0; i < win_size; ++i)
  322. new_node->rx_reorder_ptr[i] = NULL;
  323. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  324. list_add_tail(&new_node->list, &priv->rx_reorder_tbl_ptr);
  325. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  326. }
  327. /*
  328. * This function prepares command for adding a BA request.
  329. *
  330. * Preparation includes -
  331. * - Setting command ID and proper size
  332. * - Setting add BA request buffer
  333. * - Ensuring correct endian-ness
  334. */
  335. int mwifiex_cmd_11n_addba_req(struct host_cmd_ds_command *cmd, void *data_buf)
  336. {
  337. struct host_cmd_ds_11n_addba_req *add_ba_req = &cmd->params.add_ba_req;
  338. cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_REQ);
  339. cmd->size = cpu_to_le16(sizeof(*add_ba_req) + S_DS_GEN);
  340. memcpy(add_ba_req, data_buf, sizeof(*add_ba_req));
  341. return 0;
  342. }
  343. /*
  344. * This function prepares command for adding a BA response.
  345. *
  346. * Preparation includes -
  347. * - Setting command ID and proper size
  348. * - Setting add BA response buffer
  349. * - Ensuring correct endian-ness
  350. */
  351. int mwifiex_cmd_11n_addba_rsp_gen(struct mwifiex_private *priv,
  352. struct host_cmd_ds_command *cmd,
  353. struct host_cmd_ds_11n_addba_req
  354. *cmd_addba_req)
  355. {
  356. struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &cmd->params.add_ba_rsp;
  357. struct mwifiex_sta_node *sta_ptr;
  358. u32 rx_win_size = priv->add_ba_param.rx_win_size;
  359. u8 tid;
  360. int win_size;
  361. uint16_t block_ack_param_set;
  362. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  363. ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
  364. priv->adapter->is_hw_11ac_capable &&
  365. memcmp(priv->cfg_bssid, cmd_addba_req->peer_mac_addr, ETH_ALEN)) {
  366. sta_ptr = mwifiex_get_sta_entry(priv,
  367. cmd_addba_req->peer_mac_addr);
  368. if (!sta_ptr) {
  369. dev_warn(priv->adapter->dev,
  370. "BA setup with unknown TDLS peer %pM!\n",
  371. cmd_addba_req->peer_mac_addr);
  372. return -1;
  373. }
  374. if (sta_ptr->is_11ac_enabled)
  375. rx_win_size = MWIFIEX_11AC_STA_AMPDU_DEF_RXWINSIZE;
  376. }
  377. cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_RSP);
  378. cmd->size = cpu_to_le16(sizeof(*add_ba_rsp) + S_DS_GEN);
  379. memcpy(add_ba_rsp->peer_mac_addr, cmd_addba_req->peer_mac_addr,
  380. ETH_ALEN);
  381. add_ba_rsp->dialog_token = cmd_addba_req->dialog_token;
  382. add_ba_rsp->block_ack_tmo = cmd_addba_req->block_ack_tmo;
  383. add_ba_rsp->ssn = cmd_addba_req->ssn;
  384. block_ack_param_set = le16_to_cpu(cmd_addba_req->block_ack_param_set);
  385. tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK)
  386. >> BLOCKACKPARAM_TID_POS;
  387. add_ba_rsp->status_code = cpu_to_le16(ADDBA_RSP_STATUS_ACCEPT);
  388. block_ack_param_set &= ~IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK;
  389. /* If we don't support AMSDU inside AMPDU, reset the bit */
  390. if (!priv->add_ba_param.rx_amsdu ||
  391. (priv->aggr_prio_tbl[tid].amsdu == BA_STREAM_NOT_ALLOWED))
  392. block_ack_param_set &= ~BLOCKACKPARAM_AMSDU_SUPP_MASK;
  393. block_ack_param_set |= rx_win_size << BLOCKACKPARAM_WINSIZE_POS;
  394. add_ba_rsp->block_ack_param_set = cpu_to_le16(block_ack_param_set);
  395. win_size = (le16_to_cpu(add_ba_rsp->block_ack_param_set)
  396. & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK)
  397. >> BLOCKACKPARAM_WINSIZE_POS;
  398. cmd_addba_req->block_ack_param_set = cpu_to_le16(block_ack_param_set);
  399. mwifiex_11n_create_rx_reorder_tbl(priv, cmd_addba_req->peer_mac_addr,
  400. tid, win_size,
  401. le16_to_cpu(cmd_addba_req->ssn));
  402. return 0;
  403. }
  404. /*
  405. * This function prepares command for deleting a BA request.
  406. *
  407. * Preparation includes -
  408. * - Setting command ID and proper size
  409. * - Setting del BA request buffer
  410. * - Ensuring correct endian-ness
  411. */
  412. int mwifiex_cmd_11n_delba(struct host_cmd_ds_command *cmd, void *data_buf)
  413. {
  414. struct host_cmd_ds_11n_delba *del_ba = &cmd->params.del_ba;
  415. cmd->command = cpu_to_le16(HostCmd_CMD_11N_DELBA);
  416. cmd->size = cpu_to_le16(sizeof(*del_ba) + S_DS_GEN);
  417. memcpy(del_ba, data_buf, sizeof(*del_ba));
  418. return 0;
  419. }
  420. /*
  421. * This function identifies if Rx reordering is needed for a received packet.
  422. *
  423. * In case reordering is required, the function will do the reordering
  424. * before sending it to kernel.
  425. *
  426. * The Rx reorder table is checked first with the received TID/TA pair. If
  427. * not found, the received packet is dispatched immediately. But if found,
  428. * the packet is reordered and all the packets in the updated Rx reordering
  429. * table is dispatched until a hole is found.
  430. *
  431. * For sequence number less than the starting window, the packet is dropped.
  432. */
  433. int mwifiex_11n_rx_reorder_pkt(struct mwifiex_private *priv,
  434. u16 seq_num, u16 tid,
  435. u8 *ta, u8 pkt_type, void *payload)
  436. {
  437. struct mwifiex_rx_reorder_tbl *tbl;
  438. int start_win, end_win, win_size;
  439. u16 pkt_index;
  440. bool init_window_shift = false;
  441. tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta);
  442. if (!tbl) {
  443. if (pkt_type != PKT_TYPE_BAR)
  444. mwifiex_11n_dispatch_pkt(priv, payload);
  445. return 0;
  446. }
  447. if ((pkt_type == PKT_TYPE_AMSDU) && !tbl->amsdu) {
  448. mwifiex_11n_dispatch_pkt(priv, payload);
  449. return 0;
  450. }
  451. start_win = tbl->start_win;
  452. win_size = tbl->win_size;
  453. end_win = ((start_win + win_size) - 1) & (MAX_TID_VALUE - 1);
  454. if (tbl->flags & RXREOR_INIT_WINDOW_SHIFT) {
  455. init_window_shift = true;
  456. tbl->flags &= ~RXREOR_INIT_WINDOW_SHIFT;
  457. }
  458. mod_timer(&tbl->timer_context.timer,
  459. jiffies + msecs_to_jiffies(MIN_FLUSH_TIMER_MS * win_size));
  460. if (tbl->flags & RXREOR_FORCE_NO_DROP) {
  461. dev_dbg(priv->adapter->dev,
  462. "RXREOR_FORCE_NO_DROP when HS is activated\n");
  463. tbl->flags &= ~RXREOR_FORCE_NO_DROP;
  464. } else if (init_window_shift && seq_num < start_win &&
  465. seq_num >= tbl->init_win) {
  466. dev_dbg(priv->adapter->dev,
  467. "Sender TID sequence number reset %d->%d for SSN %d\n",
  468. start_win, seq_num, tbl->init_win);
  469. tbl->start_win = start_win = seq_num;
  470. end_win = ((start_win + win_size) - 1) & (MAX_TID_VALUE - 1);
  471. } else {
  472. /*
  473. * If seq_num is less then starting win then ignore and drop
  474. * the packet
  475. */
  476. if ((start_win + TWOPOW11) > (MAX_TID_VALUE - 1)) {
  477. if (seq_num >= ((start_win + TWOPOW11) &
  478. (MAX_TID_VALUE - 1)) &&
  479. seq_num < start_win)
  480. return -1;
  481. } else if ((seq_num < start_win) ||
  482. (seq_num > (start_win + TWOPOW11))) {
  483. return -1;
  484. }
  485. }
  486. /*
  487. * If this packet is a BAR we adjust seq_num as
  488. * WinStart = seq_num
  489. */
  490. if (pkt_type == PKT_TYPE_BAR)
  491. seq_num = ((seq_num + win_size) - 1) & (MAX_TID_VALUE - 1);
  492. if (((end_win < start_win) &&
  493. (seq_num < start_win) && (seq_num > end_win)) ||
  494. ((end_win > start_win) && ((seq_num > end_win) ||
  495. (seq_num < start_win)))) {
  496. end_win = seq_num;
  497. if (((seq_num - win_size) + 1) >= 0)
  498. start_win = (end_win - win_size) + 1;
  499. else
  500. start_win = (MAX_TID_VALUE - (win_size - seq_num)) + 1;
  501. mwifiex_11n_dispatch_pkt_until_start_win(priv, tbl, start_win);
  502. }
  503. if (pkt_type != PKT_TYPE_BAR) {
  504. if (seq_num >= start_win)
  505. pkt_index = seq_num - start_win;
  506. else
  507. pkt_index = (seq_num+MAX_TID_VALUE) - start_win;
  508. if (tbl->rx_reorder_ptr[pkt_index])
  509. return -1;
  510. tbl->rx_reorder_ptr[pkt_index] = payload;
  511. }
  512. /*
  513. * Dispatch all packets sequentially from start_win until a
  514. * hole is found and adjust the start_win appropriately
  515. */
  516. mwifiex_11n_scan_and_dispatch(priv, tbl);
  517. return 0;
  518. }
  519. /*
  520. * This function deletes an entry for a given TID/TA pair.
  521. *
  522. * The TID/TA are taken from del BA event body.
  523. */
  524. void
  525. mwifiex_del_ba_tbl(struct mwifiex_private *priv, int tid, u8 *peer_mac,
  526. u8 type, int initiator)
  527. {
  528. struct mwifiex_rx_reorder_tbl *tbl;
  529. struct mwifiex_tx_ba_stream_tbl *ptx_tbl;
  530. u8 cleanup_rx_reorder_tbl;
  531. unsigned long flags;
  532. if (type == TYPE_DELBA_RECEIVE)
  533. cleanup_rx_reorder_tbl = (initiator) ? true : false;
  534. else
  535. cleanup_rx_reorder_tbl = (initiator) ? false : true;
  536. dev_dbg(priv->adapter->dev, "event: DELBA: %pM tid=%d initiator=%d\n",
  537. peer_mac, tid, initiator);
  538. if (cleanup_rx_reorder_tbl) {
  539. tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid,
  540. peer_mac);
  541. if (!tbl) {
  542. dev_dbg(priv->adapter->dev,
  543. "event: TID, TA not found in table\n");
  544. return;
  545. }
  546. mwifiex_del_rx_reorder_entry(priv, tbl);
  547. } else {
  548. ptx_tbl = mwifiex_get_ba_tbl(priv, tid, peer_mac);
  549. if (!ptx_tbl) {
  550. dev_dbg(priv->adapter->dev,
  551. "event: TID, RA not found in table\n");
  552. return;
  553. }
  554. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  555. mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, ptx_tbl);
  556. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  557. }
  558. }
  559. /*
  560. * This function handles the command response of an add BA response.
  561. *
  562. * Handling includes changing the header fields into CPU format and
  563. * creating the stream, provided the add BA is accepted.
  564. */
  565. int mwifiex_ret_11n_addba_resp(struct mwifiex_private *priv,
  566. struct host_cmd_ds_command *resp)
  567. {
  568. struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &resp->params.add_ba_rsp;
  569. int tid, win_size;
  570. struct mwifiex_rx_reorder_tbl *tbl;
  571. uint16_t block_ack_param_set;
  572. block_ack_param_set = le16_to_cpu(add_ba_rsp->block_ack_param_set);
  573. tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK)
  574. >> BLOCKACKPARAM_TID_POS;
  575. /*
  576. * Check if we had rejected the ADDBA, if yes then do not create
  577. * the stream
  578. */
  579. if (le16_to_cpu(add_ba_rsp->status_code) != BA_RESULT_SUCCESS) {
  580. dev_err(priv->adapter->dev, "ADDBA RSP: failed %pM tid=%d)\n",
  581. add_ba_rsp->peer_mac_addr, tid);
  582. tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid,
  583. add_ba_rsp->peer_mac_addr);
  584. if (tbl)
  585. mwifiex_del_rx_reorder_entry(priv, tbl);
  586. return 0;
  587. }
  588. win_size = (block_ack_param_set & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK)
  589. >> BLOCKACKPARAM_WINSIZE_POS;
  590. tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid,
  591. add_ba_rsp->peer_mac_addr);
  592. if (tbl) {
  593. if ((block_ack_param_set & BLOCKACKPARAM_AMSDU_SUPP_MASK) &&
  594. priv->add_ba_param.rx_amsdu &&
  595. (priv->aggr_prio_tbl[tid].amsdu != BA_STREAM_NOT_ALLOWED))
  596. tbl->amsdu = true;
  597. else
  598. tbl->amsdu = false;
  599. }
  600. dev_dbg(priv->adapter->dev,
  601. "cmd: ADDBA RSP: %pM tid=%d ssn=%d win_size=%d\n",
  602. add_ba_rsp->peer_mac_addr, tid, add_ba_rsp->ssn, win_size);
  603. return 0;
  604. }
  605. /*
  606. * This function handles BA stream timeout event by preparing and sending
  607. * a command to the firmware.
  608. */
  609. void mwifiex_11n_ba_stream_timeout(struct mwifiex_private *priv,
  610. struct host_cmd_ds_11n_batimeout *event)
  611. {
  612. struct host_cmd_ds_11n_delba delba;
  613. memset(&delba, 0, sizeof(struct host_cmd_ds_11n_delba));
  614. memcpy(delba.peer_mac_addr, event->peer_mac_addr, ETH_ALEN);
  615. delba.del_ba_param_set |=
  616. cpu_to_le16((u16) event->tid << DELBA_TID_POS);
  617. delba.del_ba_param_set |= cpu_to_le16(
  618. (u16) event->origninator << DELBA_INITIATOR_POS);
  619. delba.reason_code = cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
  620. mwifiex_send_cmd(priv, HostCmd_CMD_11N_DELBA, 0, 0, &delba, false);
  621. }
  622. /*
  623. * This function cleans up the Rx reorder table by deleting all the entries
  624. * and re-initializing.
  625. */
  626. void mwifiex_11n_cleanup_reorder_tbl(struct mwifiex_private *priv)
  627. {
  628. struct mwifiex_rx_reorder_tbl *del_tbl_ptr, *tmp_node;
  629. unsigned long flags;
  630. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  631. list_for_each_entry_safe(del_tbl_ptr, tmp_node,
  632. &priv->rx_reorder_tbl_ptr, list) {
  633. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  634. mwifiex_del_rx_reorder_entry(priv, del_tbl_ptr);
  635. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  636. }
  637. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  638. INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
  639. mwifiex_reset_11n_rx_seq_num(priv);
  640. }
  641. /*
  642. * This function updates all rx_reorder_tbl's flags.
  643. */
  644. void mwifiex_update_rxreor_flags(struct mwifiex_adapter *adapter, u8 flags)
  645. {
  646. struct mwifiex_private *priv;
  647. struct mwifiex_rx_reorder_tbl *tbl;
  648. unsigned long lock_flags;
  649. int i;
  650. for (i = 0; i < adapter->priv_num; i++) {
  651. priv = adapter->priv[i];
  652. if (!priv)
  653. continue;
  654. if (list_empty(&priv->rx_reorder_tbl_ptr))
  655. continue;
  656. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, lock_flags);
  657. list_for_each_entry(tbl, &priv->rx_reorder_tbl_ptr, list)
  658. tbl->flags = flags;
  659. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, lock_flags);
  660. }
  661. return;
  662. }