11n.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /*
  2. * Marvell Wireless LAN device driver: 802.11n
  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. /*
  27. * Fills HT capability information field, AMPDU Parameters field, HT extended
  28. * capability field, and supported MCS set fields.
  29. *
  30. * HT capability information field, AMPDU Parameters field, supported MCS set
  31. * fields are retrieved from cfg80211 stack
  32. *
  33. * RD responder bit to set to clear in the extended capability header.
  34. */
  35. void
  36. mwifiex_fill_cap_info(struct mwifiex_private *priv, u8 radio_type,
  37. struct mwifiex_ie_types_htcap *ht_cap)
  38. {
  39. uint16_t ht_ext_cap = le16_to_cpu(ht_cap->ht_cap.extended_ht_cap_info);
  40. struct ieee80211_supported_band *sband =
  41. priv->wdev->wiphy->bands[radio_type];
  42. ht_cap->ht_cap.ampdu_params_info =
  43. (sband->ht_cap.ampdu_factor &
  44. IEEE80211_HT_AMPDU_PARM_FACTOR) |
  45. ((sband->ht_cap.ampdu_density <<
  46. IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT) &
  47. IEEE80211_HT_AMPDU_PARM_DENSITY);
  48. memcpy((u8 *) &ht_cap->ht_cap.mcs, &sband->ht_cap.mcs,
  49. sizeof(sband->ht_cap.mcs));
  50. if (priv->bss_mode == NL80211_IFTYPE_STATION ||
  51. (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
  52. (priv->adapter->sec_chan_offset !=
  53. IEEE80211_HT_PARAM_CHA_SEC_NONE)))
  54. /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
  55. SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask);
  56. /* Clear RD responder bit */
  57. ht_ext_cap &= ~IEEE80211_HT_EXT_CAP_RD_RESPONDER;
  58. ht_cap->ht_cap.cap_info = cpu_to_le16(sband->ht_cap.cap);
  59. ht_cap->ht_cap.extended_ht_cap_info = cpu_to_le16(ht_ext_cap);
  60. }
  61. /*
  62. * This function returns the pointer to an entry in BA Stream
  63. * table which matches the requested BA status.
  64. */
  65. static struct mwifiex_tx_ba_stream_tbl *
  66. mwifiex_get_ba_status(struct mwifiex_private *priv,
  67. enum mwifiex_ba_status ba_status)
  68. {
  69. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  70. unsigned long flags;
  71. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  72. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  73. if (tx_ba_tsr_tbl->ba_status == ba_status) {
  74. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
  75. flags);
  76. return tx_ba_tsr_tbl;
  77. }
  78. }
  79. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  80. return NULL;
  81. }
  82. /*
  83. * This function handles the command response of delete a block
  84. * ack request.
  85. *
  86. * The function checks the response success status and takes action
  87. * accordingly (send an add BA request in case of success, or recreate
  88. * the deleted stream in case of failure, if the add BA was also
  89. * initiated by us).
  90. */
  91. int mwifiex_ret_11n_delba(struct mwifiex_private *priv,
  92. struct host_cmd_ds_command *resp)
  93. {
  94. int tid;
  95. struct mwifiex_tx_ba_stream_tbl *tx_ba_tbl;
  96. struct host_cmd_ds_11n_delba *del_ba = &resp->params.del_ba;
  97. uint16_t del_ba_param_set = le16_to_cpu(del_ba->del_ba_param_set);
  98. tid = del_ba_param_set >> DELBA_TID_POS;
  99. if (del_ba->del_result == BA_RESULT_SUCCESS) {
  100. mwifiex_del_ba_tbl(priv, tid, del_ba->peer_mac_addr,
  101. TYPE_DELBA_SENT,
  102. INITIATOR_BIT(del_ba_param_set));
  103. tx_ba_tbl = mwifiex_get_ba_status(priv, BA_SETUP_INPROGRESS);
  104. if (tx_ba_tbl)
  105. mwifiex_send_addba(priv, tx_ba_tbl->tid,
  106. tx_ba_tbl->ra);
  107. } else { /*
  108. * In case of failure, recreate the deleted stream in case
  109. * we initiated the ADDBA
  110. */
  111. if (!INITIATOR_BIT(del_ba_param_set))
  112. return 0;
  113. mwifiex_create_ba_tbl(priv, del_ba->peer_mac_addr, tid,
  114. BA_SETUP_INPROGRESS);
  115. tx_ba_tbl = mwifiex_get_ba_status(priv, BA_SETUP_INPROGRESS);
  116. if (tx_ba_tbl)
  117. mwifiex_del_ba_tbl(priv, tx_ba_tbl->tid, tx_ba_tbl->ra,
  118. TYPE_DELBA_SENT, true);
  119. }
  120. return 0;
  121. }
  122. /*
  123. * This function handles the command response of add a block
  124. * ack request.
  125. *
  126. * Handling includes changing the header fields to CPU formats, checking
  127. * the response success status and taking actions accordingly (delete the
  128. * BA stream table in case of failure).
  129. */
  130. int mwifiex_ret_11n_addba_req(struct mwifiex_private *priv,
  131. struct host_cmd_ds_command *resp)
  132. {
  133. int tid;
  134. struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &resp->params.add_ba_rsp;
  135. struct mwifiex_tx_ba_stream_tbl *tx_ba_tbl;
  136. add_ba_rsp->ssn = cpu_to_le16((le16_to_cpu(add_ba_rsp->ssn))
  137. & SSN_MASK);
  138. tid = (le16_to_cpu(add_ba_rsp->block_ack_param_set)
  139. & IEEE80211_ADDBA_PARAM_TID_MASK)
  140. >> BLOCKACKPARAM_TID_POS;
  141. if (le16_to_cpu(add_ba_rsp->status_code) == BA_RESULT_SUCCESS) {
  142. tx_ba_tbl = mwifiex_get_ba_tbl(priv, tid,
  143. add_ba_rsp->peer_mac_addr);
  144. if (tx_ba_tbl) {
  145. dev_dbg(priv->adapter->dev, "info: BA stream complete\n");
  146. tx_ba_tbl->ba_status = BA_SETUP_COMPLETE;
  147. } else {
  148. dev_err(priv->adapter->dev, "BA stream not created\n");
  149. }
  150. } else {
  151. mwifiex_del_ba_tbl(priv, tid, add_ba_rsp->peer_mac_addr,
  152. TYPE_DELBA_SENT, true);
  153. if (add_ba_rsp->add_rsp_result != BA_RESULT_TIMEOUT)
  154. priv->aggr_prio_tbl[tid].ampdu_ap =
  155. BA_STREAM_NOT_ALLOWED;
  156. }
  157. return 0;
  158. }
  159. /*
  160. * This function prepares command of reconfigure Tx buffer.
  161. *
  162. * Preparation includes -
  163. * - Setting command ID, action and proper size
  164. * - Setting Tx buffer size (for SET only)
  165. * - Ensuring correct endian-ness
  166. */
  167. int mwifiex_cmd_recfg_tx_buf(struct mwifiex_private *priv,
  168. struct host_cmd_ds_command *cmd, int cmd_action,
  169. u16 *buf_size)
  170. {
  171. struct host_cmd_ds_txbuf_cfg *tx_buf = &cmd->params.tx_buf;
  172. u16 action = (u16) cmd_action;
  173. cmd->command = cpu_to_le16(HostCmd_CMD_RECONFIGURE_TX_BUFF);
  174. cmd->size =
  175. cpu_to_le16(sizeof(struct host_cmd_ds_txbuf_cfg) + S_DS_GEN);
  176. tx_buf->action = cpu_to_le16(action);
  177. switch (action) {
  178. case HostCmd_ACT_GEN_SET:
  179. dev_dbg(priv->adapter->dev, "cmd: set tx_buf=%d\n", *buf_size);
  180. tx_buf->buff_size = cpu_to_le16(*buf_size);
  181. break;
  182. case HostCmd_ACT_GEN_GET:
  183. default:
  184. tx_buf->buff_size = 0;
  185. break;
  186. }
  187. return 0;
  188. }
  189. /*
  190. * This function prepares command of AMSDU aggregation control.
  191. *
  192. * Preparation includes -
  193. * - Setting command ID, action and proper size
  194. * - Setting AMSDU control parameters (for SET only)
  195. * - Ensuring correct endian-ness
  196. */
  197. int mwifiex_cmd_amsdu_aggr_ctrl(struct host_cmd_ds_command *cmd,
  198. int cmd_action,
  199. struct mwifiex_ds_11n_amsdu_aggr_ctrl *aa_ctrl)
  200. {
  201. struct host_cmd_ds_amsdu_aggr_ctrl *amsdu_ctrl =
  202. &cmd->params.amsdu_aggr_ctrl;
  203. u16 action = (u16) cmd_action;
  204. cmd->command = cpu_to_le16(HostCmd_CMD_AMSDU_AGGR_CTRL);
  205. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_amsdu_aggr_ctrl)
  206. + S_DS_GEN);
  207. amsdu_ctrl->action = cpu_to_le16(action);
  208. switch (action) {
  209. case HostCmd_ACT_GEN_SET:
  210. amsdu_ctrl->enable = cpu_to_le16(aa_ctrl->enable);
  211. amsdu_ctrl->curr_buf_size = 0;
  212. break;
  213. case HostCmd_ACT_GEN_GET:
  214. default:
  215. amsdu_ctrl->curr_buf_size = 0;
  216. break;
  217. }
  218. return 0;
  219. }
  220. /*
  221. * This function prepares 11n configuration command.
  222. *
  223. * Preparation includes -
  224. * - Setting command ID, action and proper size
  225. * - Setting HT Tx capability and HT Tx information fields
  226. * - Ensuring correct endian-ness
  227. */
  228. int mwifiex_cmd_11n_cfg(struct mwifiex_private *priv,
  229. struct host_cmd_ds_command *cmd, u16 cmd_action,
  230. struct mwifiex_ds_11n_tx_cfg *txcfg)
  231. {
  232. struct host_cmd_ds_11n_cfg *htcfg = &cmd->params.htcfg;
  233. cmd->command = cpu_to_le16(HostCmd_CMD_11N_CFG);
  234. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_11n_cfg) + S_DS_GEN);
  235. htcfg->action = cpu_to_le16(cmd_action);
  236. htcfg->ht_tx_cap = cpu_to_le16(txcfg->tx_htcap);
  237. htcfg->ht_tx_info = cpu_to_le16(txcfg->tx_htinfo);
  238. if (priv->adapter->is_hw_11ac_capable)
  239. htcfg->misc_config = cpu_to_le16(txcfg->misc_config);
  240. return 0;
  241. }
  242. /*
  243. * This function appends an 11n TLV to a buffer.
  244. *
  245. * Buffer allocation is responsibility of the calling
  246. * function. No size validation is made here.
  247. *
  248. * The function fills up the following sections, if applicable -
  249. * - HT capability IE
  250. * - HT information IE (with channel list)
  251. * - 20/40 BSS Coexistence IE
  252. * - HT Extended Capabilities IE
  253. */
  254. int
  255. mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv,
  256. struct mwifiex_bssdescriptor *bss_desc,
  257. u8 **buffer)
  258. {
  259. struct mwifiex_ie_types_htcap *ht_cap;
  260. struct mwifiex_ie_types_htinfo *ht_info;
  261. struct mwifiex_ie_types_chan_list_param_set *chan_list;
  262. struct mwifiex_ie_types_2040bssco *bss_co_2040;
  263. struct mwifiex_ie_types_extcap *ext_cap;
  264. int ret_len = 0;
  265. struct ieee80211_supported_band *sband;
  266. struct ieee_types_header *hdr;
  267. u8 radio_type;
  268. if (!buffer || !*buffer)
  269. return ret_len;
  270. radio_type = mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
  271. sband = priv->wdev->wiphy->bands[radio_type];
  272. if (bss_desc->bcn_ht_cap) {
  273. ht_cap = (struct mwifiex_ie_types_htcap *) *buffer;
  274. memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
  275. ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
  276. ht_cap->header.len =
  277. cpu_to_le16(sizeof(struct ieee80211_ht_cap));
  278. memcpy((u8 *) ht_cap + sizeof(struct mwifiex_ie_types_header),
  279. (u8 *) bss_desc->bcn_ht_cap +
  280. sizeof(struct ieee_types_header),
  281. le16_to_cpu(ht_cap->header.len));
  282. mwifiex_fill_cap_info(priv, radio_type, ht_cap);
  283. *buffer += sizeof(struct mwifiex_ie_types_htcap);
  284. ret_len += sizeof(struct mwifiex_ie_types_htcap);
  285. }
  286. if (bss_desc->bcn_ht_oper) {
  287. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  288. ht_info = (struct mwifiex_ie_types_htinfo *) *buffer;
  289. memset(ht_info, 0,
  290. sizeof(struct mwifiex_ie_types_htinfo));
  291. ht_info->header.type =
  292. cpu_to_le16(WLAN_EID_HT_OPERATION);
  293. ht_info->header.len =
  294. cpu_to_le16(
  295. sizeof(struct ieee80211_ht_operation));
  296. memcpy((u8 *) ht_info +
  297. sizeof(struct mwifiex_ie_types_header),
  298. (u8 *) bss_desc->bcn_ht_oper +
  299. sizeof(struct ieee_types_header),
  300. le16_to_cpu(ht_info->header.len));
  301. if (!(sband->ht_cap.cap &
  302. IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  303. ht_info->ht_oper.ht_param &=
  304. ~(IEEE80211_HT_PARAM_CHAN_WIDTH_ANY |
  305. IEEE80211_HT_PARAM_CHA_SEC_OFFSET);
  306. *buffer += sizeof(struct mwifiex_ie_types_htinfo);
  307. ret_len += sizeof(struct mwifiex_ie_types_htinfo);
  308. }
  309. chan_list =
  310. (struct mwifiex_ie_types_chan_list_param_set *) *buffer;
  311. memset(chan_list, 0,
  312. sizeof(struct mwifiex_ie_types_chan_list_param_set));
  313. chan_list->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  314. chan_list->header.len = cpu_to_le16(
  315. sizeof(struct mwifiex_ie_types_chan_list_param_set) -
  316. sizeof(struct mwifiex_ie_types_header));
  317. chan_list->chan_scan_param[0].chan_number =
  318. bss_desc->bcn_ht_oper->primary_chan;
  319. chan_list->chan_scan_param[0].radio_type =
  320. mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
  321. if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
  322. bss_desc->bcn_ht_oper->ht_param &
  323. IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)
  324. SET_SECONDARYCHAN(chan_list->chan_scan_param[0].
  325. radio_type,
  326. (bss_desc->bcn_ht_oper->ht_param &
  327. IEEE80211_HT_PARAM_CHA_SEC_OFFSET));
  328. *buffer += sizeof(struct mwifiex_ie_types_chan_list_param_set);
  329. ret_len += sizeof(struct mwifiex_ie_types_chan_list_param_set);
  330. }
  331. if (bss_desc->bcn_bss_co_2040) {
  332. bss_co_2040 = (struct mwifiex_ie_types_2040bssco *) *buffer;
  333. memset(bss_co_2040, 0,
  334. sizeof(struct mwifiex_ie_types_2040bssco));
  335. bss_co_2040->header.type = cpu_to_le16(WLAN_EID_BSS_COEX_2040);
  336. bss_co_2040->header.len =
  337. cpu_to_le16(sizeof(bss_co_2040->bss_co_2040));
  338. memcpy((u8 *) bss_co_2040 +
  339. sizeof(struct mwifiex_ie_types_header),
  340. bss_desc->bcn_bss_co_2040 +
  341. sizeof(struct ieee_types_header),
  342. le16_to_cpu(bss_co_2040->header.len));
  343. *buffer += sizeof(struct mwifiex_ie_types_2040bssco);
  344. ret_len += sizeof(struct mwifiex_ie_types_2040bssco);
  345. }
  346. if (bss_desc->bcn_ext_cap) {
  347. hdr = (void *)bss_desc->bcn_ext_cap;
  348. ext_cap = (struct mwifiex_ie_types_extcap *) *buffer;
  349. memset(ext_cap, 0, sizeof(struct mwifiex_ie_types_extcap));
  350. ext_cap->header.type = cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
  351. ext_cap->header.len = cpu_to_le16(hdr->len);
  352. memcpy((u8 *)ext_cap->ext_capab,
  353. bss_desc->bcn_ext_cap + sizeof(struct ieee_types_header),
  354. le16_to_cpu(ext_cap->header.len));
  355. if (hdr->len > 3 &&
  356. ext_cap->ext_capab[3] & WLAN_EXT_CAPA4_INTERWORKING_ENABLED)
  357. priv->hs2_enabled = true;
  358. else
  359. priv->hs2_enabled = false;
  360. *buffer += sizeof(struct mwifiex_ie_types_extcap) + hdr->len;
  361. ret_len += sizeof(struct mwifiex_ie_types_extcap) + hdr->len;
  362. }
  363. return ret_len;
  364. }
  365. /*
  366. * This function checks if the given pointer is valid entry of
  367. * Tx BA Stream table.
  368. */
  369. static int mwifiex_is_tx_ba_stream_ptr_valid(struct mwifiex_private *priv,
  370. struct mwifiex_tx_ba_stream_tbl *tx_tbl_ptr)
  371. {
  372. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  373. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  374. if (tx_ba_tsr_tbl == tx_tbl_ptr)
  375. return true;
  376. }
  377. return false;
  378. }
  379. /*
  380. * This function deletes the given entry in Tx BA Stream table.
  381. *
  382. * The function also performs a validity check on the supplied
  383. * pointer before trying to delete.
  384. */
  385. void mwifiex_11n_delete_tx_ba_stream_tbl_entry(struct mwifiex_private *priv,
  386. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl)
  387. {
  388. if (!tx_ba_tsr_tbl &&
  389. mwifiex_is_tx_ba_stream_ptr_valid(priv, tx_ba_tsr_tbl))
  390. return;
  391. dev_dbg(priv->adapter->dev, "info: tx_ba_tsr_tbl %p\n", tx_ba_tsr_tbl);
  392. list_del(&tx_ba_tsr_tbl->list);
  393. kfree(tx_ba_tsr_tbl);
  394. }
  395. /*
  396. * This function deletes all the entries in Tx BA Stream table.
  397. */
  398. void mwifiex_11n_delete_all_tx_ba_stream_tbl(struct mwifiex_private *priv)
  399. {
  400. int i;
  401. struct mwifiex_tx_ba_stream_tbl *del_tbl_ptr, *tmp_node;
  402. unsigned long flags;
  403. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  404. list_for_each_entry_safe(del_tbl_ptr, tmp_node,
  405. &priv->tx_ba_stream_tbl_ptr, list)
  406. mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, del_tbl_ptr);
  407. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  408. INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
  409. for (i = 0; i < MAX_NUM_TID; ++i)
  410. priv->aggr_prio_tbl[i].ampdu_ap =
  411. priv->aggr_prio_tbl[i].ampdu_user;
  412. }
  413. /*
  414. * This function returns the pointer to an entry in BA Stream
  415. * table which matches the given RA/TID pair.
  416. */
  417. struct mwifiex_tx_ba_stream_tbl *
  418. mwifiex_get_ba_tbl(struct mwifiex_private *priv, int tid, u8 *ra)
  419. {
  420. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  421. unsigned long flags;
  422. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  423. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  424. if (!memcmp(tx_ba_tsr_tbl->ra, ra, ETH_ALEN) &&
  425. tx_ba_tsr_tbl->tid == tid) {
  426. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
  427. flags);
  428. return tx_ba_tsr_tbl;
  429. }
  430. }
  431. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  432. return NULL;
  433. }
  434. /*
  435. * This function creates an entry in Tx BA stream table for the
  436. * given RA/TID pair.
  437. */
  438. void mwifiex_create_ba_tbl(struct mwifiex_private *priv, u8 *ra, int tid,
  439. enum mwifiex_ba_status ba_status)
  440. {
  441. struct mwifiex_tx_ba_stream_tbl *new_node;
  442. unsigned long flags;
  443. if (!mwifiex_get_ba_tbl(priv, tid, ra)) {
  444. new_node = kzalloc(sizeof(struct mwifiex_tx_ba_stream_tbl),
  445. GFP_ATOMIC);
  446. if (!new_node)
  447. return;
  448. INIT_LIST_HEAD(&new_node->list);
  449. new_node->tid = tid;
  450. new_node->ba_status = ba_status;
  451. memcpy(new_node->ra, ra, ETH_ALEN);
  452. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  453. list_add_tail(&new_node->list, &priv->tx_ba_stream_tbl_ptr);
  454. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  455. }
  456. }
  457. /*
  458. * This function sends an add BA request to the given TID/RA pair.
  459. */
  460. int mwifiex_send_addba(struct mwifiex_private *priv, int tid, u8 *peer_mac)
  461. {
  462. struct host_cmd_ds_11n_addba_req add_ba_req;
  463. static u8 dialog_tok;
  464. int ret;
  465. dev_dbg(priv->adapter->dev, "cmd: %s: tid %d\n", __func__, tid);
  466. add_ba_req.block_ack_param_set = cpu_to_le16(
  467. (u16) ((tid << BLOCKACKPARAM_TID_POS) |
  468. (priv->add_ba_param.
  469. tx_win_size << BLOCKACKPARAM_WINSIZE_POS) |
  470. IMMEDIATE_BLOCK_ACK));
  471. add_ba_req.block_ack_tmo = cpu_to_le16((u16)priv->add_ba_param.timeout);
  472. ++dialog_tok;
  473. if (dialog_tok == 0)
  474. dialog_tok = 1;
  475. add_ba_req.dialog_token = dialog_tok;
  476. memcpy(&add_ba_req.peer_mac_addr, peer_mac, ETH_ALEN);
  477. /* We don't wait for the response of this command */
  478. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_REQ,
  479. 0, 0, &add_ba_req);
  480. return ret;
  481. }
  482. /*
  483. * This function sends a delete BA request to the given TID/RA pair.
  484. */
  485. int mwifiex_send_delba(struct mwifiex_private *priv, int tid, u8 *peer_mac,
  486. int initiator)
  487. {
  488. struct host_cmd_ds_11n_delba delba;
  489. int ret;
  490. uint16_t del_ba_param_set;
  491. memset(&delba, 0, sizeof(delba));
  492. delba.del_ba_param_set = cpu_to_le16(tid << DELBA_TID_POS);
  493. del_ba_param_set = le16_to_cpu(delba.del_ba_param_set);
  494. if (initiator)
  495. del_ba_param_set |= IEEE80211_DELBA_PARAM_INITIATOR_MASK;
  496. else
  497. del_ba_param_set &= ~IEEE80211_DELBA_PARAM_INITIATOR_MASK;
  498. memcpy(&delba.peer_mac_addr, peer_mac, ETH_ALEN);
  499. /* We don't wait for the response of this command */
  500. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_DELBA,
  501. HostCmd_ACT_GEN_SET, 0, &delba);
  502. return ret;
  503. }
  504. /*
  505. * This function handles the command response of a delete BA request.
  506. */
  507. void mwifiex_11n_delete_ba_stream(struct mwifiex_private *priv, u8 *del_ba)
  508. {
  509. struct host_cmd_ds_11n_delba *cmd_del_ba =
  510. (struct host_cmd_ds_11n_delba *) del_ba;
  511. uint16_t del_ba_param_set = le16_to_cpu(cmd_del_ba->del_ba_param_set);
  512. int tid;
  513. tid = del_ba_param_set >> DELBA_TID_POS;
  514. mwifiex_del_ba_tbl(priv, tid, cmd_del_ba->peer_mac_addr,
  515. TYPE_DELBA_RECEIVE, INITIATOR_BIT(del_ba_param_set));
  516. }
  517. /*
  518. * This function retrieves the Rx reordering table.
  519. */
  520. int mwifiex_get_rx_reorder_tbl(struct mwifiex_private *priv,
  521. struct mwifiex_ds_rx_reorder_tbl *buf)
  522. {
  523. int i;
  524. struct mwifiex_ds_rx_reorder_tbl *rx_reo_tbl = buf;
  525. struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr;
  526. int count = 0;
  527. unsigned long flags;
  528. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  529. list_for_each_entry(rx_reorder_tbl_ptr, &priv->rx_reorder_tbl_ptr,
  530. list) {
  531. rx_reo_tbl->tid = (u16) rx_reorder_tbl_ptr->tid;
  532. memcpy(rx_reo_tbl->ta, rx_reorder_tbl_ptr->ta, ETH_ALEN);
  533. rx_reo_tbl->start_win = rx_reorder_tbl_ptr->start_win;
  534. rx_reo_tbl->win_size = rx_reorder_tbl_ptr->win_size;
  535. for (i = 0; i < rx_reorder_tbl_ptr->win_size; ++i) {
  536. if (rx_reorder_tbl_ptr->rx_reorder_ptr[i])
  537. rx_reo_tbl->buffer[i] = true;
  538. else
  539. rx_reo_tbl->buffer[i] = false;
  540. }
  541. rx_reo_tbl++;
  542. count++;
  543. if (count >= MWIFIEX_MAX_RX_BASTREAM_SUPPORTED)
  544. break;
  545. }
  546. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  547. return count;
  548. }
  549. /*
  550. * This function retrieves the Tx BA stream table.
  551. */
  552. int mwifiex_get_tx_ba_stream_tbl(struct mwifiex_private *priv,
  553. struct mwifiex_ds_tx_ba_stream_tbl *buf)
  554. {
  555. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  556. struct mwifiex_ds_tx_ba_stream_tbl *rx_reo_tbl = buf;
  557. int count = 0;
  558. unsigned long flags;
  559. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  560. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  561. rx_reo_tbl->tid = (u16) tx_ba_tsr_tbl->tid;
  562. dev_dbg(priv->adapter->dev, "data: %s tid=%d\n",
  563. __func__, rx_reo_tbl->tid);
  564. memcpy(rx_reo_tbl->ra, tx_ba_tsr_tbl->ra, ETH_ALEN);
  565. rx_reo_tbl++;
  566. count++;
  567. if (count >= MWIFIEX_MAX_TX_BASTREAM_SUPPORTED)
  568. break;
  569. }
  570. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  571. return count;
  572. }
  573. /*
  574. * This function retrieves the entry for specific tx BA stream table by RA and
  575. * deletes it.
  576. */
  577. void mwifiex_del_tx_ba_stream_tbl_by_ra(struct mwifiex_private *priv, u8 *ra)
  578. {
  579. struct mwifiex_tx_ba_stream_tbl *tbl, *tmp;
  580. unsigned long flags;
  581. if (!ra)
  582. return;
  583. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  584. list_for_each_entry_safe(tbl, tmp, &priv->tx_ba_stream_tbl_ptr, list) {
  585. if (!memcmp(tbl->ra, ra, ETH_ALEN)) {
  586. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
  587. flags);
  588. mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, tbl);
  589. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  590. }
  591. }
  592. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  593. return;
  594. }
  595. /* This function initializes the BlockACK setup information for given
  596. * mwifiex_private structure.
  597. */
  598. void mwifiex_set_ba_params(struct mwifiex_private *priv)
  599. {
  600. priv->add_ba_param.timeout = MWIFIEX_DEFAULT_BLOCK_ACK_TIMEOUT;
  601. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
  602. priv->add_ba_param.tx_win_size =
  603. MWIFIEX_UAP_AMPDU_DEF_TXWINSIZE;
  604. priv->add_ba_param.rx_win_size =
  605. MWIFIEX_UAP_AMPDU_DEF_RXWINSIZE;
  606. } else {
  607. priv->add_ba_param.tx_win_size =
  608. MWIFIEX_STA_AMPDU_DEF_TXWINSIZE;
  609. priv->add_ba_param.rx_win_size =
  610. MWIFIEX_STA_AMPDU_DEF_RXWINSIZE;
  611. }
  612. return;
  613. }