11n.c 23 KB

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