11n_rxreorder.c 23 KB

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