11n.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  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. /* Update HT40 capability from current channel information */
  307. if (bss_desc->bcn_ht_oper) {
  308. u8 ht_param = bss_desc->bcn_ht_oper->ht_param;
  309. u8 radio =
  310. mwifiex_band_to_radio_type(bss_desc->bss_band);
  311. int freq =
  312. ieee80211_channel_to_frequency(bss_desc->channel,
  313. radio);
  314. struct ieee80211_channel *chan =
  315. ieee80211_get_channel(priv->adapter->wiphy, freq);
  316. switch (ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  317. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  318. if (chan->flags & IEEE80211_CHAN_NO_HT40PLUS) {
  319. ht_cap->ht_cap.cap_info &=
  320. cpu_to_le16
  321. (~IEEE80211_HT_CAP_SUP_WIDTH_20_40);
  322. ht_cap->ht_cap.cap_info &=
  323. cpu_to_le16(~IEEE80211_HT_CAP_SGI_40);
  324. }
  325. break;
  326. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  327. if (chan->flags & IEEE80211_CHAN_NO_HT40MINUS) {
  328. ht_cap->ht_cap.cap_info &=
  329. cpu_to_le16
  330. (~IEEE80211_HT_CAP_SUP_WIDTH_20_40);
  331. ht_cap->ht_cap.cap_info &=
  332. cpu_to_le16(~IEEE80211_HT_CAP_SGI_40);
  333. }
  334. break;
  335. }
  336. }
  337. *buffer += sizeof(struct mwifiex_ie_types_htcap);
  338. ret_len += sizeof(struct mwifiex_ie_types_htcap);
  339. }
  340. if (bss_desc->bcn_ht_oper) {
  341. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  342. ht_info = (struct mwifiex_ie_types_htinfo *) *buffer;
  343. memset(ht_info, 0,
  344. sizeof(struct mwifiex_ie_types_htinfo));
  345. ht_info->header.type =
  346. cpu_to_le16(WLAN_EID_HT_OPERATION);
  347. ht_info->header.len =
  348. cpu_to_le16(
  349. sizeof(struct ieee80211_ht_operation));
  350. memcpy((u8 *) ht_info +
  351. sizeof(struct mwifiex_ie_types_header),
  352. (u8 *)bss_desc->bcn_ht_oper,
  353. le16_to_cpu(ht_info->header.len));
  354. if (!(sband->ht_cap.cap &
  355. IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  356. ht_info->ht_oper.ht_param &=
  357. ~(IEEE80211_HT_PARAM_CHAN_WIDTH_ANY |
  358. IEEE80211_HT_PARAM_CHA_SEC_OFFSET);
  359. *buffer += sizeof(struct mwifiex_ie_types_htinfo);
  360. ret_len += sizeof(struct mwifiex_ie_types_htinfo);
  361. }
  362. chan_list =
  363. (struct mwifiex_ie_types_chan_list_param_set *) *buffer;
  364. memset(chan_list, 0,
  365. sizeof(struct mwifiex_ie_types_chan_list_param_set));
  366. chan_list->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  367. chan_list->header.len = cpu_to_le16(
  368. sizeof(struct mwifiex_ie_types_chan_list_param_set) -
  369. sizeof(struct mwifiex_ie_types_header));
  370. chan_list->chan_scan_param[0].chan_number =
  371. bss_desc->bcn_ht_oper->primary_chan;
  372. chan_list->chan_scan_param[0].radio_type =
  373. mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
  374. if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
  375. bss_desc->bcn_ht_oper->ht_param &
  376. IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)
  377. SET_SECONDARYCHAN(chan_list->chan_scan_param[0].
  378. radio_type,
  379. (bss_desc->bcn_ht_oper->ht_param &
  380. IEEE80211_HT_PARAM_CHA_SEC_OFFSET));
  381. *buffer += sizeof(struct mwifiex_ie_types_chan_list_param_set);
  382. ret_len += sizeof(struct mwifiex_ie_types_chan_list_param_set);
  383. }
  384. if (bss_desc->bcn_bss_co_2040) {
  385. bss_co_2040 = (struct mwifiex_ie_types_2040bssco *) *buffer;
  386. memset(bss_co_2040, 0,
  387. sizeof(struct mwifiex_ie_types_2040bssco));
  388. bss_co_2040->header.type = cpu_to_le16(WLAN_EID_BSS_COEX_2040);
  389. bss_co_2040->header.len =
  390. cpu_to_le16(sizeof(bss_co_2040->bss_co_2040));
  391. memcpy((u8 *) bss_co_2040 +
  392. sizeof(struct mwifiex_ie_types_header),
  393. bss_desc->bcn_bss_co_2040 +
  394. sizeof(struct ieee_types_header),
  395. le16_to_cpu(bss_co_2040->header.len));
  396. *buffer += sizeof(struct mwifiex_ie_types_2040bssco);
  397. ret_len += sizeof(struct mwifiex_ie_types_2040bssco);
  398. }
  399. if (bss_desc->bcn_ext_cap) {
  400. hdr = (void *)bss_desc->bcn_ext_cap;
  401. ext_cap = (struct mwifiex_ie_types_extcap *) *buffer;
  402. memset(ext_cap, 0, sizeof(struct mwifiex_ie_types_extcap));
  403. ext_cap->header.type = cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
  404. ext_cap->header.len = cpu_to_le16(hdr->len);
  405. memcpy((u8 *)ext_cap->ext_capab,
  406. bss_desc->bcn_ext_cap + sizeof(struct ieee_types_header),
  407. le16_to_cpu(ext_cap->header.len));
  408. if (hdr->len > 3 &&
  409. ext_cap->ext_capab[3] & WLAN_EXT_CAPA4_INTERWORKING_ENABLED)
  410. priv->hs2_enabled = true;
  411. else
  412. priv->hs2_enabled = false;
  413. *buffer += sizeof(struct mwifiex_ie_types_extcap) + hdr->len;
  414. ret_len += sizeof(struct mwifiex_ie_types_extcap) + hdr->len;
  415. }
  416. return ret_len;
  417. }
  418. /*
  419. * This function checks if the given pointer is valid entry of
  420. * Tx BA Stream table.
  421. */
  422. static int mwifiex_is_tx_ba_stream_ptr_valid(struct mwifiex_private *priv,
  423. struct mwifiex_tx_ba_stream_tbl *tx_tbl_ptr)
  424. {
  425. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  426. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  427. if (tx_ba_tsr_tbl == tx_tbl_ptr)
  428. return true;
  429. }
  430. return false;
  431. }
  432. /*
  433. * This function deletes the given entry in Tx BA Stream table.
  434. *
  435. * The function also performs a validity check on the supplied
  436. * pointer before trying to delete.
  437. */
  438. void mwifiex_11n_delete_tx_ba_stream_tbl_entry(struct mwifiex_private *priv,
  439. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl)
  440. {
  441. if (!tx_ba_tsr_tbl &&
  442. mwifiex_is_tx_ba_stream_ptr_valid(priv, tx_ba_tsr_tbl))
  443. return;
  444. mwifiex_dbg(priv->adapter, INFO,
  445. "info: tx_ba_tsr_tbl %p\n", tx_ba_tsr_tbl);
  446. list_del(&tx_ba_tsr_tbl->list);
  447. kfree(tx_ba_tsr_tbl);
  448. }
  449. /*
  450. * This function deletes all the entries in Tx BA Stream table.
  451. */
  452. void mwifiex_11n_delete_all_tx_ba_stream_tbl(struct mwifiex_private *priv)
  453. {
  454. int i;
  455. struct mwifiex_tx_ba_stream_tbl *del_tbl_ptr, *tmp_node;
  456. unsigned long flags;
  457. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  458. list_for_each_entry_safe(del_tbl_ptr, tmp_node,
  459. &priv->tx_ba_stream_tbl_ptr, list)
  460. mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, del_tbl_ptr);
  461. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  462. INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
  463. for (i = 0; i < MAX_NUM_TID; ++i)
  464. priv->aggr_prio_tbl[i].ampdu_ap =
  465. priv->aggr_prio_tbl[i].ampdu_user;
  466. }
  467. /*
  468. * This function returns the pointer to an entry in BA Stream
  469. * table which matches the given RA/TID pair.
  470. */
  471. struct mwifiex_tx_ba_stream_tbl *
  472. mwifiex_get_ba_tbl(struct mwifiex_private *priv, int tid, u8 *ra)
  473. {
  474. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  475. unsigned long flags;
  476. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  477. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  478. if (ether_addr_equal_unaligned(tx_ba_tsr_tbl->ra, ra) &&
  479. tx_ba_tsr_tbl->tid == tid) {
  480. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
  481. flags);
  482. return tx_ba_tsr_tbl;
  483. }
  484. }
  485. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  486. return NULL;
  487. }
  488. /*
  489. * This function creates an entry in Tx BA stream table for the
  490. * given RA/TID pair.
  491. */
  492. void mwifiex_create_ba_tbl(struct mwifiex_private *priv, u8 *ra, int tid,
  493. enum mwifiex_ba_status ba_status)
  494. {
  495. struct mwifiex_tx_ba_stream_tbl *new_node;
  496. struct mwifiex_ra_list_tbl *ra_list;
  497. unsigned long flags;
  498. int tid_down;
  499. if (!mwifiex_get_ba_tbl(priv, tid, ra)) {
  500. new_node = kzalloc(sizeof(struct mwifiex_tx_ba_stream_tbl),
  501. GFP_ATOMIC);
  502. if (!new_node)
  503. return;
  504. tid_down = mwifiex_wmm_downgrade_tid(priv, tid);
  505. ra_list = mwifiex_wmm_get_ralist_node(priv, tid_down, ra);
  506. if (ra_list) {
  507. ra_list->ba_status = ba_status;
  508. ra_list->amsdu_in_ampdu = false;
  509. }
  510. INIT_LIST_HEAD(&new_node->list);
  511. new_node->tid = tid;
  512. new_node->ba_status = ba_status;
  513. memcpy(new_node->ra, ra, ETH_ALEN);
  514. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  515. list_add_tail(&new_node->list, &priv->tx_ba_stream_tbl_ptr);
  516. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  517. }
  518. }
  519. /*
  520. * This function sends an add BA request to the given TID/RA pair.
  521. */
  522. int mwifiex_send_addba(struct mwifiex_private *priv, int tid, u8 *peer_mac)
  523. {
  524. struct host_cmd_ds_11n_addba_req add_ba_req;
  525. u32 tx_win_size = priv->add_ba_param.tx_win_size;
  526. static u8 dialog_tok;
  527. int ret;
  528. unsigned long flags;
  529. u16 block_ack_param_set;
  530. mwifiex_dbg(priv->adapter, CMD, "cmd: %s: tid %d\n", __func__, tid);
  531. memset(&add_ba_req, 0, sizeof(add_ba_req));
  532. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  533. ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
  534. priv->adapter->is_hw_11ac_capable &&
  535. memcmp(priv->cfg_bssid, peer_mac, ETH_ALEN)) {
  536. struct mwifiex_sta_node *sta_ptr;
  537. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  538. sta_ptr = mwifiex_get_sta_entry(priv, peer_mac);
  539. if (!sta_ptr) {
  540. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  541. mwifiex_dbg(priv->adapter, ERROR,
  542. "BA setup with unknown TDLS peer %pM!\n",
  543. peer_mac);
  544. return -1;
  545. }
  546. if (sta_ptr->is_11ac_enabled)
  547. tx_win_size = MWIFIEX_11AC_STA_AMPDU_DEF_TXWINSIZE;
  548. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  549. }
  550. block_ack_param_set = (u16)((tid << BLOCKACKPARAM_TID_POS) |
  551. tx_win_size << BLOCKACKPARAM_WINSIZE_POS |
  552. IMMEDIATE_BLOCK_ACK);
  553. /* enable AMSDU inside AMPDU */
  554. if (priv->add_ba_param.tx_amsdu &&
  555. (priv->aggr_prio_tbl[tid].amsdu != BA_STREAM_NOT_ALLOWED))
  556. block_ack_param_set |= BLOCKACKPARAM_AMSDU_SUPP_MASK;
  557. add_ba_req.block_ack_param_set = cpu_to_le16(block_ack_param_set);
  558. add_ba_req.block_ack_tmo = cpu_to_le16((u16)priv->add_ba_param.timeout);
  559. ++dialog_tok;
  560. if (dialog_tok == 0)
  561. dialog_tok = 1;
  562. add_ba_req.dialog_token = dialog_tok;
  563. memcpy(&add_ba_req.peer_mac_addr, peer_mac, ETH_ALEN);
  564. /* We don't wait for the response of this command */
  565. ret = mwifiex_send_cmd(priv, HostCmd_CMD_11N_ADDBA_REQ,
  566. 0, 0, &add_ba_req, false);
  567. return ret;
  568. }
  569. /*
  570. * This function sends a delete BA request to the given TID/RA pair.
  571. */
  572. int mwifiex_send_delba(struct mwifiex_private *priv, int tid, u8 *peer_mac,
  573. int initiator)
  574. {
  575. struct host_cmd_ds_11n_delba delba;
  576. int ret;
  577. uint16_t del_ba_param_set;
  578. memset(&delba, 0, sizeof(delba));
  579. delba.del_ba_param_set = cpu_to_le16(tid << DELBA_TID_POS);
  580. del_ba_param_set = le16_to_cpu(delba.del_ba_param_set);
  581. if (initiator)
  582. del_ba_param_set |= IEEE80211_DELBA_PARAM_INITIATOR_MASK;
  583. else
  584. del_ba_param_set &= ~IEEE80211_DELBA_PARAM_INITIATOR_MASK;
  585. memcpy(&delba.peer_mac_addr, peer_mac, ETH_ALEN);
  586. /* We don't wait for the response of this command */
  587. ret = mwifiex_send_cmd(priv, HostCmd_CMD_11N_DELBA,
  588. HostCmd_ACT_GEN_SET, 0, &delba, false);
  589. return ret;
  590. }
  591. /*
  592. * This function sends delba to specific tid
  593. */
  594. void mwifiex_11n_delba(struct mwifiex_private *priv, int tid)
  595. {
  596. struct mwifiex_rx_reorder_tbl *rx_reor_tbl_ptr;
  597. unsigned long flags;
  598. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  599. list_for_each_entry(rx_reor_tbl_ptr, &priv->rx_reorder_tbl_ptr, list) {
  600. if (rx_reor_tbl_ptr->tid == tid) {
  601. dev_dbg(priv->adapter->dev,
  602. "Send delba to tid=%d, %pM\n",
  603. tid, rx_reor_tbl_ptr->ta);
  604. mwifiex_send_delba(priv, tid, rx_reor_tbl_ptr->ta, 0);
  605. goto exit;
  606. }
  607. }
  608. exit:
  609. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  610. }
  611. /*
  612. * This function handles the command response of a delete BA request.
  613. */
  614. void mwifiex_11n_delete_ba_stream(struct mwifiex_private *priv, u8 *del_ba)
  615. {
  616. struct host_cmd_ds_11n_delba *cmd_del_ba =
  617. (struct host_cmd_ds_11n_delba *) del_ba;
  618. uint16_t del_ba_param_set = le16_to_cpu(cmd_del_ba->del_ba_param_set);
  619. int tid;
  620. tid = del_ba_param_set >> DELBA_TID_POS;
  621. mwifiex_del_ba_tbl(priv, tid, cmd_del_ba->peer_mac_addr,
  622. TYPE_DELBA_RECEIVE, INITIATOR_BIT(del_ba_param_set));
  623. }
  624. /*
  625. * This function retrieves the Rx reordering table.
  626. */
  627. int mwifiex_get_rx_reorder_tbl(struct mwifiex_private *priv,
  628. struct mwifiex_ds_rx_reorder_tbl *buf)
  629. {
  630. int i;
  631. struct mwifiex_ds_rx_reorder_tbl *rx_reo_tbl = buf;
  632. struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr;
  633. int count = 0;
  634. unsigned long flags;
  635. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  636. list_for_each_entry(rx_reorder_tbl_ptr, &priv->rx_reorder_tbl_ptr,
  637. list) {
  638. rx_reo_tbl->tid = (u16) rx_reorder_tbl_ptr->tid;
  639. memcpy(rx_reo_tbl->ta, rx_reorder_tbl_ptr->ta, ETH_ALEN);
  640. rx_reo_tbl->start_win = rx_reorder_tbl_ptr->start_win;
  641. rx_reo_tbl->win_size = rx_reorder_tbl_ptr->win_size;
  642. for (i = 0; i < rx_reorder_tbl_ptr->win_size; ++i) {
  643. if (rx_reorder_tbl_ptr->rx_reorder_ptr[i])
  644. rx_reo_tbl->buffer[i] = true;
  645. else
  646. rx_reo_tbl->buffer[i] = false;
  647. }
  648. rx_reo_tbl++;
  649. count++;
  650. if (count >= MWIFIEX_MAX_RX_BASTREAM_SUPPORTED)
  651. break;
  652. }
  653. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  654. return count;
  655. }
  656. /*
  657. * This function retrieves the Tx BA stream table.
  658. */
  659. int mwifiex_get_tx_ba_stream_tbl(struct mwifiex_private *priv,
  660. struct mwifiex_ds_tx_ba_stream_tbl *buf)
  661. {
  662. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  663. struct mwifiex_ds_tx_ba_stream_tbl *rx_reo_tbl = buf;
  664. int count = 0;
  665. unsigned long flags;
  666. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  667. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  668. rx_reo_tbl->tid = (u16) tx_ba_tsr_tbl->tid;
  669. mwifiex_dbg(priv->adapter, DATA, "data: %s tid=%d\n",
  670. __func__, rx_reo_tbl->tid);
  671. memcpy(rx_reo_tbl->ra, tx_ba_tsr_tbl->ra, ETH_ALEN);
  672. rx_reo_tbl->amsdu = tx_ba_tsr_tbl->amsdu;
  673. rx_reo_tbl++;
  674. count++;
  675. if (count >= MWIFIEX_MAX_TX_BASTREAM_SUPPORTED)
  676. break;
  677. }
  678. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  679. return count;
  680. }
  681. /*
  682. * This function retrieves the entry for specific tx BA stream table by RA and
  683. * deletes it.
  684. */
  685. void mwifiex_del_tx_ba_stream_tbl_by_ra(struct mwifiex_private *priv, u8 *ra)
  686. {
  687. struct mwifiex_tx_ba_stream_tbl *tbl, *tmp;
  688. unsigned long flags;
  689. if (!ra)
  690. return;
  691. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  692. list_for_each_entry_safe(tbl, tmp, &priv->tx_ba_stream_tbl_ptr, list)
  693. if (!memcmp(tbl->ra, ra, ETH_ALEN))
  694. mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, tbl);
  695. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  696. return;
  697. }
  698. /* This function initializes the BlockACK setup information for given
  699. * mwifiex_private structure.
  700. */
  701. void mwifiex_set_ba_params(struct mwifiex_private *priv)
  702. {
  703. priv->add_ba_param.timeout = MWIFIEX_DEFAULT_BLOCK_ACK_TIMEOUT;
  704. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
  705. priv->add_ba_param.tx_win_size =
  706. MWIFIEX_UAP_AMPDU_DEF_TXWINSIZE;
  707. priv->add_ba_param.rx_win_size =
  708. MWIFIEX_UAP_AMPDU_DEF_RXWINSIZE;
  709. } else {
  710. priv->add_ba_param.tx_win_size =
  711. MWIFIEX_STA_AMPDU_DEF_TXWINSIZE;
  712. priv->add_ba_param.rx_win_size =
  713. MWIFIEX_STA_AMPDU_DEF_RXWINSIZE;
  714. }
  715. priv->add_ba_param.tx_amsdu = true;
  716. priv->add_ba_param.rx_amsdu = true;
  717. return;
  718. }
  719. u8 mwifiex_get_sec_chan_offset(int chan)
  720. {
  721. u8 sec_offset;
  722. switch (chan) {
  723. case 36:
  724. case 44:
  725. case 52:
  726. case 60:
  727. case 100:
  728. case 108:
  729. case 116:
  730. case 124:
  731. case 132:
  732. case 140:
  733. case 149:
  734. case 157:
  735. sec_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  736. break;
  737. case 40:
  738. case 48:
  739. case 56:
  740. case 64:
  741. case 104:
  742. case 112:
  743. case 120:
  744. case 128:
  745. case 136:
  746. case 144:
  747. case 153:
  748. case 161:
  749. sec_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  750. break;
  751. case 165:
  752. default:
  753. sec_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
  754. break;
  755. }
  756. return sec_offset;
  757. }
  758. /* This function will send DELBA to entries in the priv's
  759. * Tx BA stream table
  760. */
  761. static void
  762. mwifiex_send_delba_txbastream_tbl(struct mwifiex_private *priv, u8 tid)
  763. {
  764. struct mwifiex_adapter *adapter = priv->adapter;
  765. struct mwifiex_tx_ba_stream_tbl *tx_ba_stream_tbl_ptr;
  766. list_for_each_entry(tx_ba_stream_tbl_ptr,
  767. &priv->tx_ba_stream_tbl_ptr, list) {
  768. if (tx_ba_stream_tbl_ptr->ba_status == BA_SETUP_COMPLETE) {
  769. if (tid == tx_ba_stream_tbl_ptr->tid) {
  770. dev_dbg(adapter->dev,
  771. "Tx:Send delba to tid=%d, %pM\n", tid,
  772. tx_ba_stream_tbl_ptr->ra);
  773. mwifiex_send_delba(priv,
  774. tx_ba_stream_tbl_ptr->tid,
  775. tx_ba_stream_tbl_ptr->ra, 1);
  776. return;
  777. }
  778. }
  779. }
  780. }
  781. /* This function updates all the tx_win_size
  782. */
  783. void mwifiex_update_ampdu_txwinsize(struct mwifiex_adapter *adapter)
  784. {
  785. u8 i;
  786. u32 tx_win_size;
  787. struct mwifiex_private *priv;
  788. for (i = 0; i < adapter->priv_num; i++) {
  789. if (!adapter->priv[i])
  790. continue;
  791. priv = adapter->priv[i];
  792. tx_win_size = priv->add_ba_param.tx_win_size;
  793. if (priv->bss_type == MWIFIEX_BSS_TYPE_STA)
  794. priv->add_ba_param.tx_win_size =
  795. MWIFIEX_STA_AMPDU_DEF_TXWINSIZE;
  796. if (priv->bss_type == MWIFIEX_BSS_TYPE_P2P)
  797. priv->add_ba_param.tx_win_size =
  798. MWIFIEX_STA_AMPDU_DEF_TXWINSIZE;
  799. if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP)
  800. priv->add_ba_param.tx_win_size =
  801. MWIFIEX_UAP_AMPDU_DEF_TXWINSIZE;
  802. if (adapter->coex_win_size) {
  803. if (adapter->coex_tx_win_size)
  804. priv->add_ba_param.tx_win_size =
  805. adapter->coex_tx_win_size;
  806. }
  807. if (tx_win_size != priv->add_ba_param.tx_win_size) {
  808. if (!priv->media_connected)
  809. continue;
  810. for (i = 0; i < MAX_NUM_TID; i++)
  811. mwifiex_send_delba_txbastream_tbl(priv, i);
  812. }
  813. }
  814. }