11n.c 26 KB

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