11n.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  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. mwifiex_dbg(priv->adapter, ERROR, "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, tid_down;
  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. struct mwifiex_ra_list_tbl *ra_list;
  143. u16 block_ack_param_set = le16_to_cpu(add_ba_rsp->block_ack_param_set);
  144. add_ba_rsp->ssn = cpu_to_le16((le16_to_cpu(add_ba_rsp->ssn))
  145. & SSN_MASK);
  146. tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK)
  147. >> BLOCKACKPARAM_TID_POS;
  148. tid_down = mwifiex_wmm_downgrade_tid(priv, tid);
  149. ra_list = mwifiex_wmm_get_ralist_node(priv, tid_down, add_ba_rsp->
  150. peer_mac_addr);
  151. if (le16_to_cpu(add_ba_rsp->status_code) != BA_RESULT_SUCCESS) {
  152. if (ra_list) {
  153. ra_list->ba_status = BA_SETUP_NONE;
  154. ra_list->amsdu_in_ampdu = false;
  155. }
  156. mwifiex_del_ba_tbl(priv, tid, add_ba_rsp->peer_mac_addr,
  157. TYPE_DELBA_SENT, true);
  158. if (add_ba_rsp->add_rsp_result != BA_RESULT_TIMEOUT)
  159. priv->aggr_prio_tbl[tid].ampdu_ap =
  160. BA_STREAM_NOT_ALLOWED;
  161. return 0;
  162. }
  163. tx_ba_tbl = mwifiex_get_ba_tbl(priv, tid, add_ba_rsp->peer_mac_addr);
  164. if (tx_ba_tbl) {
  165. mwifiex_dbg(priv->adapter, EVENT, "info: BA stream complete\n");
  166. tx_ba_tbl->ba_status = BA_SETUP_COMPLETE;
  167. if ((block_ack_param_set & BLOCKACKPARAM_AMSDU_SUPP_MASK) &&
  168. priv->add_ba_param.tx_amsdu &&
  169. (priv->aggr_prio_tbl[tid].amsdu != BA_STREAM_NOT_ALLOWED))
  170. tx_ba_tbl->amsdu = true;
  171. else
  172. tx_ba_tbl->amsdu = false;
  173. if (ra_list) {
  174. ra_list->amsdu_in_ampdu = tx_ba_tbl->amsdu;
  175. ra_list->ba_status = BA_SETUP_COMPLETE;
  176. }
  177. } else {
  178. mwifiex_dbg(priv->adapter, ERROR, "BA stream not created\n");
  179. }
  180. return 0;
  181. }
  182. /*
  183. * This function prepares command of reconfigure Tx buffer.
  184. *
  185. * Preparation includes -
  186. * - Setting command ID, action and proper size
  187. * - Setting Tx buffer size (for SET only)
  188. * - Ensuring correct endian-ness
  189. */
  190. int mwifiex_cmd_recfg_tx_buf(struct mwifiex_private *priv,
  191. struct host_cmd_ds_command *cmd, int cmd_action,
  192. u16 *buf_size)
  193. {
  194. struct host_cmd_ds_txbuf_cfg *tx_buf = &cmd->params.tx_buf;
  195. u16 action = (u16) cmd_action;
  196. cmd->command = cpu_to_le16(HostCmd_CMD_RECONFIGURE_TX_BUFF);
  197. cmd->size =
  198. cpu_to_le16(sizeof(struct host_cmd_ds_txbuf_cfg) + S_DS_GEN);
  199. tx_buf->action = cpu_to_le16(action);
  200. switch (action) {
  201. case HostCmd_ACT_GEN_SET:
  202. mwifiex_dbg(priv->adapter, CMD,
  203. "cmd: set tx_buf=%d\n", *buf_size);
  204. tx_buf->buff_size = cpu_to_le16(*buf_size);
  205. break;
  206. case HostCmd_ACT_GEN_GET:
  207. default:
  208. tx_buf->buff_size = 0;
  209. break;
  210. }
  211. return 0;
  212. }
  213. /*
  214. * This function prepares command of AMSDU aggregation control.
  215. *
  216. * Preparation includes -
  217. * - Setting command ID, action and proper size
  218. * - Setting AMSDU control parameters (for SET only)
  219. * - Ensuring correct endian-ness
  220. */
  221. int mwifiex_cmd_amsdu_aggr_ctrl(struct host_cmd_ds_command *cmd,
  222. int cmd_action,
  223. struct mwifiex_ds_11n_amsdu_aggr_ctrl *aa_ctrl)
  224. {
  225. struct host_cmd_ds_amsdu_aggr_ctrl *amsdu_ctrl =
  226. &cmd->params.amsdu_aggr_ctrl;
  227. u16 action = (u16) cmd_action;
  228. cmd->command = cpu_to_le16(HostCmd_CMD_AMSDU_AGGR_CTRL);
  229. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_amsdu_aggr_ctrl)
  230. + S_DS_GEN);
  231. amsdu_ctrl->action = cpu_to_le16(action);
  232. switch (action) {
  233. case HostCmd_ACT_GEN_SET:
  234. amsdu_ctrl->enable = cpu_to_le16(aa_ctrl->enable);
  235. amsdu_ctrl->curr_buf_size = 0;
  236. break;
  237. case HostCmd_ACT_GEN_GET:
  238. default:
  239. amsdu_ctrl->curr_buf_size = 0;
  240. break;
  241. }
  242. return 0;
  243. }
  244. /*
  245. * This function prepares 11n configuration command.
  246. *
  247. * Preparation includes -
  248. * - Setting command ID, action and proper size
  249. * - Setting HT Tx capability and HT Tx information fields
  250. * - Ensuring correct endian-ness
  251. */
  252. int mwifiex_cmd_11n_cfg(struct mwifiex_private *priv,
  253. struct host_cmd_ds_command *cmd, u16 cmd_action,
  254. struct mwifiex_ds_11n_tx_cfg *txcfg)
  255. {
  256. struct host_cmd_ds_11n_cfg *htcfg = &cmd->params.htcfg;
  257. cmd->command = cpu_to_le16(HostCmd_CMD_11N_CFG);
  258. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_11n_cfg) + S_DS_GEN);
  259. htcfg->action = cpu_to_le16(cmd_action);
  260. htcfg->ht_tx_cap = cpu_to_le16(txcfg->tx_htcap);
  261. htcfg->ht_tx_info = cpu_to_le16(txcfg->tx_htinfo);
  262. if (priv->adapter->is_hw_11ac_capable)
  263. htcfg->misc_config = cpu_to_le16(txcfg->misc_config);
  264. return 0;
  265. }
  266. /*
  267. * This function appends an 11n TLV to a buffer.
  268. *
  269. * Buffer allocation is responsibility of the calling
  270. * function. No size validation is made here.
  271. *
  272. * The function fills up the following sections, if applicable -
  273. * - HT capability IE
  274. * - HT information IE (with channel list)
  275. * - 20/40 BSS Coexistence IE
  276. * - HT Extended Capabilities IE
  277. */
  278. int
  279. mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv,
  280. struct mwifiex_bssdescriptor *bss_desc,
  281. u8 **buffer)
  282. {
  283. struct mwifiex_ie_types_htcap *ht_cap;
  284. struct mwifiex_ie_types_htinfo *ht_info;
  285. struct mwifiex_ie_types_chan_list_param_set *chan_list;
  286. struct mwifiex_ie_types_2040bssco *bss_co_2040;
  287. struct mwifiex_ie_types_extcap *ext_cap;
  288. int ret_len = 0;
  289. struct ieee80211_supported_band *sband;
  290. struct ieee_types_header *hdr;
  291. u8 radio_type;
  292. if (!buffer || !*buffer)
  293. return ret_len;
  294. radio_type = mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
  295. sband = priv->wdev.wiphy->bands[radio_type];
  296. if (bss_desc->bcn_ht_cap) {
  297. ht_cap = (struct mwifiex_ie_types_htcap *) *buffer;
  298. memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
  299. ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
  300. ht_cap->header.len =
  301. cpu_to_le16(sizeof(struct ieee80211_ht_cap));
  302. memcpy((u8 *) ht_cap + sizeof(struct mwifiex_ie_types_header),
  303. (u8 *)bss_desc->bcn_ht_cap,
  304. le16_to_cpu(ht_cap->header.len));
  305. mwifiex_fill_cap_info(priv, radio_type, &ht_cap->ht_cap);
  306. *buffer += sizeof(struct mwifiex_ie_types_htcap);
  307. ret_len += sizeof(struct mwifiex_ie_types_htcap);
  308. }
  309. if (bss_desc->bcn_ht_oper) {
  310. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  311. ht_info = (struct mwifiex_ie_types_htinfo *) *buffer;
  312. memset(ht_info, 0,
  313. sizeof(struct mwifiex_ie_types_htinfo));
  314. ht_info->header.type =
  315. cpu_to_le16(WLAN_EID_HT_OPERATION);
  316. ht_info->header.len =
  317. cpu_to_le16(
  318. sizeof(struct ieee80211_ht_operation));
  319. memcpy((u8 *) ht_info +
  320. sizeof(struct mwifiex_ie_types_header),
  321. (u8 *)bss_desc->bcn_ht_oper,
  322. le16_to_cpu(ht_info->header.len));
  323. if (!(sband->ht_cap.cap &
  324. IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  325. ht_info->ht_oper.ht_param &=
  326. ~(IEEE80211_HT_PARAM_CHAN_WIDTH_ANY |
  327. IEEE80211_HT_PARAM_CHA_SEC_OFFSET);
  328. *buffer += sizeof(struct mwifiex_ie_types_htinfo);
  329. ret_len += sizeof(struct mwifiex_ie_types_htinfo);
  330. }
  331. chan_list =
  332. (struct mwifiex_ie_types_chan_list_param_set *) *buffer;
  333. memset(chan_list, 0,
  334. sizeof(struct mwifiex_ie_types_chan_list_param_set));
  335. chan_list->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  336. chan_list->header.len = cpu_to_le16(
  337. sizeof(struct mwifiex_ie_types_chan_list_param_set) -
  338. sizeof(struct mwifiex_ie_types_header));
  339. chan_list->chan_scan_param[0].chan_number =
  340. bss_desc->bcn_ht_oper->primary_chan;
  341. chan_list->chan_scan_param[0].radio_type =
  342. mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
  343. if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
  344. bss_desc->bcn_ht_oper->ht_param &
  345. IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)
  346. SET_SECONDARYCHAN(chan_list->chan_scan_param[0].
  347. radio_type,
  348. (bss_desc->bcn_ht_oper->ht_param &
  349. IEEE80211_HT_PARAM_CHA_SEC_OFFSET));
  350. *buffer += sizeof(struct mwifiex_ie_types_chan_list_param_set);
  351. ret_len += sizeof(struct mwifiex_ie_types_chan_list_param_set);
  352. }
  353. if (bss_desc->bcn_bss_co_2040) {
  354. bss_co_2040 = (struct mwifiex_ie_types_2040bssco *) *buffer;
  355. memset(bss_co_2040, 0,
  356. sizeof(struct mwifiex_ie_types_2040bssco));
  357. bss_co_2040->header.type = cpu_to_le16(WLAN_EID_BSS_COEX_2040);
  358. bss_co_2040->header.len =
  359. cpu_to_le16(sizeof(bss_co_2040->bss_co_2040));
  360. memcpy((u8 *) bss_co_2040 +
  361. sizeof(struct mwifiex_ie_types_header),
  362. bss_desc->bcn_bss_co_2040 +
  363. sizeof(struct ieee_types_header),
  364. le16_to_cpu(bss_co_2040->header.len));
  365. *buffer += sizeof(struct mwifiex_ie_types_2040bssco);
  366. ret_len += sizeof(struct mwifiex_ie_types_2040bssco);
  367. }
  368. if (bss_desc->bcn_ext_cap) {
  369. hdr = (void *)bss_desc->bcn_ext_cap;
  370. ext_cap = (struct mwifiex_ie_types_extcap *) *buffer;
  371. memset(ext_cap, 0, sizeof(struct mwifiex_ie_types_extcap));
  372. ext_cap->header.type = cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
  373. ext_cap->header.len = cpu_to_le16(hdr->len);
  374. memcpy((u8 *)ext_cap->ext_capab,
  375. bss_desc->bcn_ext_cap + sizeof(struct ieee_types_header),
  376. le16_to_cpu(ext_cap->header.len));
  377. if (hdr->len > 3 &&
  378. ext_cap->ext_capab[3] & WLAN_EXT_CAPA4_INTERWORKING_ENABLED)
  379. priv->hs2_enabled = true;
  380. else
  381. priv->hs2_enabled = false;
  382. *buffer += sizeof(struct mwifiex_ie_types_extcap) + hdr->len;
  383. ret_len += sizeof(struct mwifiex_ie_types_extcap) + hdr->len;
  384. }
  385. return ret_len;
  386. }
  387. /*
  388. * This function checks if the given pointer is valid entry of
  389. * Tx BA Stream table.
  390. */
  391. static int mwifiex_is_tx_ba_stream_ptr_valid(struct mwifiex_private *priv,
  392. struct mwifiex_tx_ba_stream_tbl *tx_tbl_ptr)
  393. {
  394. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  395. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  396. if (tx_ba_tsr_tbl == tx_tbl_ptr)
  397. return true;
  398. }
  399. return false;
  400. }
  401. /*
  402. * This function deletes the given entry in Tx BA Stream table.
  403. *
  404. * The function also performs a validity check on the supplied
  405. * pointer before trying to delete.
  406. */
  407. void mwifiex_11n_delete_tx_ba_stream_tbl_entry(struct mwifiex_private *priv,
  408. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl)
  409. {
  410. if (!tx_ba_tsr_tbl &&
  411. mwifiex_is_tx_ba_stream_ptr_valid(priv, tx_ba_tsr_tbl))
  412. return;
  413. mwifiex_dbg(priv->adapter, INFO,
  414. "info: tx_ba_tsr_tbl %p\n", tx_ba_tsr_tbl);
  415. list_del(&tx_ba_tsr_tbl->list);
  416. kfree(tx_ba_tsr_tbl);
  417. }
  418. /*
  419. * This function deletes all the entries in Tx BA Stream table.
  420. */
  421. void mwifiex_11n_delete_all_tx_ba_stream_tbl(struct mwifiex_private *priv)
  422. {
  423. int i;
  424. struct mwifiex_tx_ba_stream_tbl *del_tbl_ptr, *tmp_node;
  425. unsigned long flags;
  426. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  427. list_for_each_entry_safe(del_tbl_ptr, tmp_node,
  428. &priv->tx_ba_stream_tbl_ptr, list)
  429. mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, del_tbl_ptr);
  430. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  431. INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
  432. for (i = 0; i < MAX_NUM_TID; ++i)
  433. priv->aggr_prio_tbl[i].ampdu_ap =
  434. priv->aggr_prio_tbl[i].ampdu_user;
  435. }
  436. /*
  437. * This function returns the pointer to an entry in BA Stream
  438. * table which matches the given RA/TID pair.
  439. */
  440. struct mwifiex_tx_ba_stream_tbl *
  441. mwifiex_get_ba_tbl(struct mwifiex_private *priv, int tid, u8 *ra)
  442. {
  443. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  444. unsigned long flags;
  445. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  446. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  447. if (ether_addr_equal_unaligned(tx_ba_tsr_tbl->ra, ra) &&
  448. tx_ba_tsr_tbl->tid == tid) {
  449. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
  450. flags);
  451. return tx_ba_tsr_tbl;
  452. }
  453. }
  454. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  455. return NULL;
  456. }
  457. /*
  458. * This function creates an entry in Tx BA stream table for the
  459. * given RA/TID pair.
  460. */
  461. void mwifiex_create_ba_tbl(struct mwifiex_private *priv, u8 *ra, int tid,
  462. enum mwifiex_ba_status ba_status)
  463. {
  464. struct mwifiex_tx_ba_stream_tbl *new_node;
  465. struct mwifiex_ra_list_tbl *ra_list;
  466. unsigned long flags;
  467. int tid_down;
  468. if (!mwifiex_get_ba_tbl(priv, tid, ra)) {
  469. new_node = kzalloc(sizeof(struct mwifiex_tx_ba_stream_tbl),
  470. GFP_ATOMIC);
  471. if (!new_node)
  472. return;
  473. tid_down = mwifiex_wmm_downgrade_tid(priv, tid);
  474. ra_list = mwifiex_wmm_get_ralist_node(priv, tid_down, ra);
  475. if (ra_list) {
  476. ra_list->ba_status = ba_status;
  477. ra_list->amsdu_in_ampdu = false;
  478. }
  479. INIT_LIST_HEAD(&new_node->list);
  480. new_node->tid = tid;
  481. new_node->ba_status = ba_status;
  482. memcpy(new_node->ra, ra, ETH_ALEN);
  483. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  484. list_add_tail(&new_node->list, &priv->tx_ba_stream_tbl_ptr);
  485. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  486. }
  487. }
  488. /*
  489. * This function sends an add BA request to the given TID/RA pair.
  490. */
  491. int mwifiex_send_addba(struct mwifiex_private *priv, int tid, u8 *peer_mac)
  492. {
  493. struct host_cmd_ds_11n_addba_req add_ba_req;
  494. u32 tx_win_size = priv->add_ba_param.tx_win_size;
  495. static u8 dialog_tok;
  496. int ret;
  497. unsigned long flags;
  498. u16 block_ack_param_set;
  499. mwifiex_dbg(priv->adapter, CMD, "cmd: %s: tid %d\n", __func__, tid);
  500. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  501. ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
  502. priv->adapter->is_hw_11ac_capable &&
  503. memcmp(priv->cfg_bssid, peer_mac, ETH_ALEN)) {
  504. struct mwifiex_sta_node *sta_ptr;
  505. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  506. sta_ptr = mwifiex_get_sta_entry(priv, peer_mac);
  507. if (!sta_ptr) {
  508. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  509. mwifiex_dbg(priv->adapter, ERROR,
  510. "BA setup with unknown TDLS peer %pM!\n",
  511. peer_mac);
  512. return -1;
  513. }
  514. if (sta_ptr->is_11ac_enabled)
  515. tx_win_size = MWIFIEX_11AC_STA_AMPDU_DEF_TXWINSIZE;
  516. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  517. }
  518. block_ack_param_set = (u16)((tid << BLOCKACKPARAM_TID_POS) |
  519. tx_win_size << BLOCKACKPARAM_WINSIZE_POS |
  520. IMMEDIATE_BLOCK_ACK);
  521. /* enable AMSDU inside AMPDU */
  522. if (priv->add_ba_param.tx_amsdu &&
  523. (priv->aggr_prio_tbl[tid].amsdu != BA_STREAM_NOT_ALLOWED))
  524. block_ack_param_set |= BLOCKACKPARAM_AMSDU_SUPP_MASK;
  525. add_ba_req.block_ack_param_set = cpu_to_le16(block_ack_param_set);
  526. add_ba_req.block_ack_tmo = cpu_to_le16((u16)priv->add_ba_param.timeout);
  527. ++dialog_tok;
  528. if (dialog_tok == 0)
  529. dialog_tok = 1;
  530. add_ba_req.dialog_token = dialog_tok;
  531. memcpy(&add_ba_req.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_ADDBA_REQ,
  534. 0, 0, &add_ba_req, false);
  535. return ret;
  536. }
  537. /*
  538. * This function sends a delete BA request to the given TID/RA pair.
  539. */
  540. int mwifiex_send_delba(struct mwifiex_private *priv, int tid, u8 *peer_mac,
  541. int initiator)
  542. {
  543. struct host_cmd_ds_11n_delba delba;
  544. int ret;
  545. uint16_t del_ba_param_set;
  546. memset(&delba, 0, sizeof(delba));
  547. delba.del_ba_param_set = cpu_to_le16(tid << DELBA_TID_POS);
  548. del_ba_param_set = le16_to_cpu(delba.del_ba_param_set);
  549. if (initiator)
  550. del_ba_param_set |= IEEE80211_DELBA_PARAM_INITIATOR_MASK;
  551. else
  552. del_ba_param_set &= ~IEEE80211_DELBA_PARAM_INITIATOR_MASK;
  553. memcpy(&delba.peer_mac_addr, peer_mac, ETH_ALEN);
  554. /* We don't wait for the response of this command */
  555. ret = mwifiex_send_cmd(priv, HostCmd_CMD_11N_DELBA,
  556. HostCmd_ACT_GEN_SET, 0, &delba, false);
  557. return ret;
  558. }
  559. /*
  560. * This function sends delba to specific tid
  561. */
  562. void mwifiex_11n_delba(struct mwifiex_private *priv, int tid)
  563. {
  564. struct mwifiex_rx_reorder_tbl *rx_reor_tbl_ptr;
  565. if (list_empty(&priv->rx_reorder_tbl_ptr)) {
  566. dev_dbg(priv->adapter->dev,
  567. "mwifiex_11n_delba: rx_reorder_tbl_ptr empty\n");
  568. return;
  569. }
  570. list_for_each_entry(rx_reor_tbl_ptr, &priv->rx_reorder_tbl_ptr, list) {
  571. if (rx_reor_tbl_ptr->tid == tid) {
  572. dev_dbg(priv->adapter->dev,
  573. "Send delba to tid=%d, %pM\n",
  574. tid, rx_reor_tbl_ptr->ta);
  575. mwifiex_send_delba(priv, tid, rx_reor_tbl_ptr->ta, 0);
  576. return;
  577. }
  578. }
  579. }
  580. /*
  581. * This function handles the command response of a delete BA request.
  582. */
  583. void mwifiex_11n_delete_ba_stream(struct mwifiex_private *priv, u8 *del_ba)
  584. {
  585. struct host_cmd_ds_11n_delba *cmd_del_ba =
  586. (struct host_cmd_ds_11n_delba *) del_ba;
  587. uint16_t del_ba_param_set = le16_to_cpu(cmd_del_ba->del_ba_param_set);
  588. int tid;
  589. tid = del_ba_param_set >> DELBA_TID_POS;
  590. mwifiex_del_ba_tbl(priv, tid, cmd_del_ba->peer_mac_addr,
  591. TYPE_DELBA_RECEIVE, INITIATOR_BIT(del_ba_param_set));
  592. }
  593. /*
  594. * This function retrieves the Rx reordering table.
  595. */
  596. int mwifiex_get_rx_reorder_tbl(struct mwifiex_private *priv,
  597. struct mwifiex_ds_rx_reorder_tbl *buf)
  598. {
  599. int i;
  600. struct mwifiex_ds_rx_reorder_tbl *rx_reo_tbl = buf;
  601. struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr;
  602. int count = 0;
  603. unsigned long flags;
  604. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  605. list_for_each_entry(rx_reorder_tbl_ptr, &priv->rx_reorder_tbl_ptr,
  606. list) {
  607. rx_reo_tbl->tid = (u16) rx_reorder_tbl_ptr->tid;
  608. memcpy(rx_reo_tbl->ta, rx_reorder_tbl_ptr->ta, ETH_ALEN);
  609. rx_reo_tbl->start_win = rx_reorder_tbl_ptr->start_win;
  610. rx_reo_tbl->win_size = rx_reorder_tbl_ptr->win_size;
  611. for (i = 0; i < rx_reorder_tbl_ptr->win_size; ++i) {
  612. if (rx_reorder_tbl_ptr->rx_reorder_ptr[i])
  613. rx_reo_tbl->buffer[i] = true;
  614. else
  615. rx_reo_tbl->buffer[i] = false;
  616. }
  617. rx_reo_tbl++;
  618. count++;
  619. if (count >= MWIFIEX_MAX_RX_BASTREAM_SUPPORTED)
  620. break;
  621. }
  622. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  623. return count;
  624. }
  625. /*
  626. * This function retrieves the Tx BA stream table.
  627. */
  628. int mwifiex_get_tx_ba_stream_tbl(struct mwifiex_private *priv,
  629. struct mwifiex_ds_tx_ba_stream_tbl *buf)
  630. {
  631. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  632. struct mwifiex_ds_tx_ba_stream_tbl *rx_reo_tbl = buf;
  633. int count = 0;
  634. unsigned long flags;
  635. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  636. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  637. rx_reo_tbl->tid = (u16) tx_ba_tsr_tbl->tid;
  638. mwifiex_dbg(priv->adapter, DATA, "data: %s tid=%d\n",
  639. __func__, rx_reo_tbl->tid);
  640. memcpy(rx_reo_tbl->ra, tx_ba_tsr_tbl->ra, ETH_ALEN);
  641. rx_reo_tbl->amsdu = tx_ba_tsr_tbl->amsdu;
  642. rx_reo_tbl++;
  643. count++;
  644. if (count >= MWIFIEX_MAX_TX_BASTREAM_SUPPORTED)
  645. break;
  646. }
  647. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  648. return count;
  649. }
  650. /*
  651. * This function retrieves the entry for specific tx BA stream table by RA and
  652. * deletes it.
  653. */
  654. void mwifiex_del_tx_ba_stream_tbl_by_ra(struct mwifiex_private *priv, u8 *ra)
  655. {
  656. struct mwifiex_tx_ba_stream_tbl *tbl, *tmp;
  657. unsigned long flags;
  658. if (!ra)
  659. return;
  660. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  661. list_for_each_entry_safe(tbl, tmp, &priv->tx_ba_stream_tbl_ptr, list) {
  662. if (!memcmp(tbl->ra, ra, ETH_ALEN)) {
  663. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
  664. flags);
  665. mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, tbl);
  666. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  667. }
  668. }
  669. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  670. return;
  671. }
  672. /* This function initializes the BlockACK setup information for given
  673. * mwifiex_private structure.
  674. */
  675. void mwifiex_set_ba_params(struct mwifiex_private *priv)
  676. {
  677. priv->add_ba_param.timeout = MWIFIEX_DEFAULT_BLOCK_ACK_TIMEOUT;
  678. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
  679. priv->add_ba_param.tx_win_size =
  680. MWIFIEX_UAP_AMPDU_DEF_TXWINSIZE;
  681. priv->add_ba_param.rx_win_size =
  682. MWIFIEX_UAP_AMPDU_DEF_RXWINSIZE;
  683. } else {
  684. priv->add_ba_param.tx_win_size =
  685. MWIFIEX_STA_AMPDU_DEF_TXWINSIZE;
  686. priv->add_ba_param.rx_win_size =
  687. MWIFIEX_STA_AMPDU_DEF_RXWINSIZE;
  688. }
  689. priv->add_ba_param.tx_amsdu = true;
  690. priv->add_ba_param.rx_amsdu = true;
  691. return;
  692. }
  693. u8 mwifiex_get_sec_chan_offset(int chan)
  694. {
  695. u8 sec_offset;
  696. switch (chan) {
  697. case 36:
  698. case 44:
  699. case 52:
  700. case 60:
  701. case 100:
  702. case 108:
  703. case 116:
  704. case 124:
  705. case 132:
  706. case 140:
  707. case 149:
  708. case 157:
  709. sec_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  710. break;
  711. case 40:
  712. case 48:
  713. case 56:
  714. case 64:
  715. case 104:
  716. case 112:
  717. case 120:
  718. case 128:
  719. case 136:
  720. case 144:
  721. case 153:
  722. case 161:
  723. sec_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  724. break;
  725. case 165:
  726. default:
  727. sec_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
  728. break;
  729. }
  730. return sec_offset;
  731. }
  732. /* This function will send DELBA to entries in the priv's
  733. * Tx BA stream table
  734. */
  735. static void
  736. mwifiex_send_delba_txbastream_tbl(struct mwifiex_private *priv, u8 tid)
  737. {
  738. struct mwifiex_adapter *adapter = priv->adapter;
  739. struct mwifiex_tx_ba_stream_tbl *tx_ba_stream_tbl_ptr;
  740. if (list_empty(&priv->tx_ba_stream_tbl_ptr))
  741. return;
  742. list_for_each_entry(tx_ba_stream_tbl_ptr,
  743. &priv->tx_ba_stream_tbl_ptr, list) {
  744. if (tx_ba_stream_tbl_ptr->ba_status == BA_SETUP_COMPLETE) {
  745. if (tid == tx_ba_stream_tbl_ptr->tid) {
  746. dev_dbg(adapter->dev,
  747. "Tx:Send delba to tid=%d, %pM\n", tid,
  748. tx_ba_stream_tbl_ptr->ra);
  749. mwifiex_send_delba(priv,
  750. tx_ba_stream_tbl_ptr->tid,
  751. tx_ba_stream_tbl_ptr->ra, 1);
  752. return;
  753. }
  754. }
  755. }
  756. }
  757. /* This function updates all the tx_win_size
  758. */
  759. void mwifiex_update_ampdu_txwinsize(struct mwifiex_adapter *adapter)
  760. {
  761. u8 i;
  762. u32 tx_win_size;
  763. struct mwifiex_private *priv;
  764. for (i = 0; i < adapter->priv_num; i++) {
  765. if (!adapter->priv[i])
  766. continue;
  767. priv = adapter->priv[i];
  768. tx_win_size = priv->add_ba_param.tx_win_size;
  769. if (priv->bss_type == MWIFIEX_BSS_TYPE_STA)
  770. priv->add_ba_param.tx_win_size =
  771. MWIFIEX_STA_AMPDU_DEF_TXWINSIZE;
  772. if (priv->bss_type == MWIFIEX_BSS_TYPE_P2P)
  773. priv->add_ba_param.tx_win_size =
  774. MWIFIEX_STA_AMPDU_DEF_TXWINSIZE;
  775. if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP)
  776. priv->add_ba_param.tx_win_size =
  777. MWIFIEX_UAP_AMPDU_DEF_TXWINSIZE;
  778. if (adapter->coex_win_size) {
  779. if (adapter->coex_tx_win_size)
  780. priv->add_ba_param.tx_win_size =
  781. adapter->coex_tx_win_size;
  782. }
  783. if (tx_win_size != priv->add_ba_param.tx_win_size) {
  784. if (!priv->media_connected)
  785. continue;
  786. for (i = 0; i < MAX_NUM_TID; i++)
  787. mwifiex_send_delba_txbastream_tbl(priv, i);
  788. }
  789. }
  790. }