11n.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. /*
  2. * Marvell Wireless LAN device driver: 802.11n
  3. *
  4. * Copyright (C) 2011, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include "decl.h"
  20. #include "ioctl.h"
  21. #include "util.h"
  22. #include "fw.h"
  23. #include "main.h"
  24. #include "wmm.h"
  25. #include "11n.h"
  26. /*
  27. * Fills HT capability information field, AMPDU Parameters field, HT extended
  28. * capability field, and supported MCS set fields.
  29. *
  30. * Only the following HT capability information fields are used, all other
  31. * fields are always turned off.
  32. *
  33. * Bit 1 : Supported channel width (0: 20MHz, 1: Both 20 and 40 MHz)
  34. * Bit 4 : Greenfield support (0: Not supported, 1: Supported)
  35. * Bit 5 : Short GI for 20 MHz support (0: Not supported, 1: Supported)
  36. * Bit 6 : Short GI for 40 MHz support (0: Not supported, 1: Supported)
  37. * Bit 7 : Tx STBC (0: Not supported, 1: Supported)
  38. * Bit 8-9 : Rx STBC (0: Not supported, X: Support for up to X spatial streams)
  39. * Bit 10 : Delayed BA support (0: Not supported, 1: Supported)
  40. * Bit 11 : Maximum AMSDU length (0: 3839 octets, 1: 7935 octets)
  41. * Bit 14 : 40-Mhz intolerant support (0: Not supported, 1: Supported)
  42. *
  43. * In addition, the following AMPDU Parameters are set -
  44. * - Maximum AMPDU length exponent (set to 3)
  45. * - Minimum AMPDU start spacing (set to 0 - No restrictions)
  46. *
  47. * MCS is set for 1x1, with MSC32 for infra mode or ad-hoc mode with 40 MHz
  48. * support.
  49. *
  50. * RD responder bit to set to clear in the extended capability header.
  51. */
  52. void
  53. mwifiex_fill_cap_info(struct mwifiex_private *priv,
  54. struct mwifiex_ie_types_htcap *ht_cap)
  55. {
  56. struct mwifiex_adapter *adapter = priv->adapter;
  57. u8 *mcs;
  58. int rx_mcs_supp;
  59. uint16_t ht_cap_info = le16_to_cpu(ht_cap->ht_cap.cap_info);
  60. uint16_t ht_ext_cap = le16_to_cpu(ht_cap->ht_cap.extended_ht_cap_info);
  61. if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap) &&
  62. ISSUPP_CHANWIDTH40(adapter->usr_dot_11n_dev_cap))
  63. SETHT_SUPPCHANWIDTH(ht_cap_info);
  64. else
  65. RESETHT_SUPPCHANWIDTH(ht_cap_info);
  66. if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap) &&
  67. ISSUPP_GREENFIELD(adapter->usr_dot_11n_dev_cap))
  68. SETHT_GREENFIELD(ht_cap_info);
  69. else
  70. RESETHT_GREENFIELD(ht_cap_info);
  71. if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap) &&
  72. ISSUPP_SHORTGI20(adapter->usr_dot_11n_dev_cap))
  73. SETHT_SHORTGI20(ht_cap_info);
  74. else
  75. RESETHT_SHORTGI20(ht_cap_info);
  76. if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap) &&
  77. ISSUPP_SHORTGI40(adapter->usr_dot_11n_dev_cap))
  78. SETHT_SHORTGI40(ht_cap_info);
  79. else
  80. RESETHT_SHORTGI40(ht_cap_info);
  81. /* No user config for RX STBC yet */
  82. if (ISSUPP_RXSTBC(adapter->hw_dot_11n_dev_cap)
  83. && ISSUPP_RXSTBC(adapter->usr_dot_11n_dev_cap))
  84. SETHT_RXSTBC(ht_cap_info, 1);
  85. else
  86. RESETHT_RXSTBC(ht_cap_info);
  87. /* No user config for TX STBC yet */
  88. if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
  89. SETHT_TXSTBC(ht_cap_info);
  90. else
  91. RESETHT_TXSTBC(ht_cap_info);
  92. /* No user config for Delayed BACK yet */
  93. if (GET_DELAYEDBACK(adapter->hw_dot_11n_dev_cap))
  94. SETHT_DELAYEDBACK(ht_cap_info);
  95. else
  96. RESETHT_DELAYEDBACK(ht_cap_info);
  97. if (ISENABLED_40MHZ_INTOLARENT(adapter->usr_dot_11n_dev_cap))
  98. SETHT_40MHZ_INTOLARANT(ht_cap_info);
  99. else
  100. RESETHT_40MHZ_INTOLARANT(ht_cap_info);
  101. SETAMPDU_SIZE(ht_cap->ht_cap.ampdu_params_info, AMPDU_FACTOR_64K);
  102. SETAMPDU_SPACING(ht_cap->ht_cap.ampdu_params_info, 0);
  103. /* Need change to support 8k AMSDU receive */
  104. RESETHT_MAXAMSDU(ht_cap_info);
  105. rx_mcs_supp = GET_RXMCSSUPP(adapter->hw_dev_mcs_support);
  106. mcs = (u8 *)&ht_cap->ht_cap.mcs;
  107. /* Set MCS for 1x1 */
  108. memset(mcs, 0xff, rx_mcs_supp);
  109. /* Clear all the other values */
  110. memset(&mcs[rx_mcs_supp], 0,
  111. sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
  112. if (priv->bss_mode == MWIFIEX_BSS_MODE_INFRA ||
  113. (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap) &&
  114. ISSUPP_CHANWIDTH40(adapter->usr_dot_11n_dev_cap)))
  115. /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
  116. SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask);
  117. /* Clear RD responder bit */
  118. RESETHT_EXTCAP_RDG(ht_ext_cap);
  119. ht_cap->ht_cap.cap_info = cpu_to_le16(ht_cap_info);
  120. ht_cap->ht_cap.extended_ht_cap_info = cpu_to_le16(ht_ext_cap);
  121. }
  122. /*
  123. * This function returns the pointer to an entry in BA Stream
  124. * table which matches the requested BA status.
  125. */
  126. static struct mwifiex_tx_ba_stream_tbl *
  127. mwifiex_11n_get_tx_ba_stream_status(struct mwifiex_private *priv,
  128. enum mwifiex_ba_status ba_status)
  129. {
  130. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  131. unsigned long flags;
  132. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  133. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  134. if (tx_ba_tsr_tbl->ba_status == ba_status) {
  135. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
  136. flags);
  137. return tx_ba_tsr_tbl;
  138. }
  139. }
  140. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  141. return NULL;
  142. }
  143. /*
  144. * This function handles the command response of delete a block
  145. * ack request.
  146. *
  147. * The function checks the response success status and takes action
  148. * accordingly (send an add BA request in case of success, or recreate
  149. * the deleted stream in case of failure, if the add BA was also
  150. * initiated by us).
  151. */
  152. int mwifiex_ret_11n_delba(struct mwifiex_private *priv,
  153. struct host_cmd_ds_command *resp)
  154. {
  155. int tid;
  156. struct mwifiex_tx_ba_stream_tbl *tx_ba_tbl;
  157. struct host_cmd_ds_11n_delba *del_ba =
  158. (struct host_cmd_ds_11n_delba *) &resp->params.del_ba;
  159. uint16_t del_ba_param_set = le16_to_cpu(del_ba->del_ba_param_set);
  160. tid = del_ba_param_set >> DELBA_TID_POS;
  161. if (del_ba->del_result == BA_RESULT_SUCCESS) {
  162. mwifiex_11n_delete_ba_stream_tbl(priv, tid,
  163. del_ba->peer_mac_addr, TYPE_DELBA_SENT,
  164. INITIATOR_BIT(del_ba_param_set));
  165. tx_ba_tbl = mwifiex_11n_get_tx_ba_stream_status(priv,
  166. BA_STREAM_SETUP_INPROGRESS);
  167. if (tx_ba_tbl)
  168. mwifiex_send_addba(priv, tx_ba_tbl->tid,
  169. tx_ba_tbl->ra);
  170. } else { /*
  171. * In case of failure, recreate the deleted stream in case
  172. * we initiated the ADDBA
  173. */
  174. if (INITIATOR_BIT(del_ba_param_set)) {
  175. mwifiex_11n_create_tx_ba_stream_tbl(priv,
  176. del_ba->peer_mac_addr, tid,
  177. BA_STREAM_SETUP_INPROGRESS);
  178. tx_ba_tbl = mwifiex_11n_get_tx_ba_stream_status(priv,
  179. BA_STREAM_SETUP_INPROGRESS);
  180. if (tx_ba_tbl)
  181. mwifiex_11n_delete_ba_stream_tbl(priv,
  182. tx_ba_tbl->tid, tx_ba_tbl->ra,
  183. TYPE_DELBA_SENT, true);
  184. }
  185. }
  186. return 0;
  187. }
  188. /*
  189. * This function handles the command response of add a block
  190. * ack request.
  191. *
  192. * Handling includes changing the header fields to CPU formats, checking
  193. * the response success status and taking actions accordingly (delete the
  194. * BA stream table in case of failure).
  195. */
  196. int mwifiex_ret_11n_addba_req(struct mwifiex_private *priv,
  197. struct host_cmd_ds_command *resp)
  198. {
  199. int tid;
  200. struct host_cmd_ds_11n_addba_rsp *add_ba_rsp =
  201. (struct host_cmd_ds_11n_addba_rsp *) &resp->params.add_ba_rsp;
  202. struct mwifiex_tx_ba_stream_tbl *tx_ba_tbl;
  203. add_ba_rsp->ssn = cpu_to_le16((le16_to_cpu(add_ba_rsp->ssn))
  204. & SSN_MASK);
  205. tid = (le16_to_cpu(add_ba_rsp->block_ack_param_set)
  206. & IEEE80211_ADDBA_PARAM_TID_MASK)
  207. >> BLOCKACKPARAM_TID_POS;
  208. if (le16_to_cpu(add_ba_rsp->status_code) == BA_RESULT_SUCCESS) {
  209. tx_ba_tbl = mwifiex_11n_get_tx_ba_stream_tbl(priv, tid,
  210. add_ba_rsp->peer_mac_addr);
  211. if (tx_ba_tbl) {
  212. dev_dbg(priv->adapter->dev, "info: BA stream complete\n");
  213. tx_ba_tbl->ba_status = BA_STREAM_SETUP_COMPLETE;
  214. } else {
  215. dev_err(priv->adapter->dev, "BA stream not created\n");
  216. }
  217. } else {
  218. mwifiex_11n_delete_ba_stream_tbl(priv, tid,
  219. add_ba_rsp->peer_mac_addr,
  220. TYPE_DELBA_SENT, true);
  221. if (add_ba_rsp->add_rsp_result != BA_RESULT_TIMEOUT)
  222. priv->aggr_prio_tbl[tid].ampdu_ap =
  223. BA_STREAM_NOT_ALLOWED;
  224. }
  225. return 0;
  226. }
  227. /*
  228. * This function handles the command response of 11n configuration request.
  229. *
  230. * Handling includes changing the header fields into CPU format.
  231. */
  232. int mwifiex_ret_11n_cfg(struct mwifiex_private *priv,
  233. struct host_cmd_ds_command *resp,
  234. void *data_buf)
  235. {
  236. struct mwifiex_ds_11n_tx_cfg *tx_cfg = NULL;
  237. struct host_cmd_ds_11n_cfg *htcfg = &resp->params.htcfg;
  238. if (data_buf) {
  239. tx_cfg = (struct mwifiex_ds_11n_tx_cfg *) data_buf;
  240. tx_cfg->tx_htcap = le16_to_cpu(htcfg->ht_tx_cap);
  241. tx_cfg->tx_htinfo = le16_to_cpu(htcfg->ht_tx_info);
  242. }
  243. return 0;
  244. }
  245. /*
  246. * This function prepares command of reconfigure Tx buffer.
  247. *
  248. * Preparation includes -
  249. * - Setting command ID, action and proper size
  250. * - Setting Tx buffer size (for SET only)
  251. * - Ensuring correct endian-ness
  252. */
  253. int mwifiex_cmd_recfg_tx_buf(struct mwifiex_private *priv,
  254. struct host_cmd_ds_command *cmd, int cmd_action,
  255. void *data_buf)
  256. {
  257. struct host_cmd_ds_txbuf_cfg *tx_buf = &cmd->params.tx_buf;
  258. u16 action = (u16) cmd_action;
  259. u16 buf_size = *((u16 *) data_buf);
  260. cmd->command = cpu_to_le16(HostCmd_CMD_RECONFIGURE_TX_BUFF);
  261. cmd->size =
  262. cpu_to_le16(sizeof(struct host_cmd_ds_txbuf_cfg) + S_DS_GEN);
  263. tx_buf->action = cpu_to_le16(action);
  264. switch (action) {
  265. case HostCmd_ACT_GEN_SET:
  266. dev_dbg(priv->adapter->dev, "cmd: set tx_buf=%d\n", buf_size);
  267. tx_buf->buff_size = cpu_to_le16(buf_size);
  268. break;
  269. case HostCmd_ACT_GEN_GET:
  270. default:
  271. tx_buf->buff_size = 0;
  272. break;
  273. }
  274. return 0;
  275. }
  276. /*
  277. * This function prepares command of AMSDU aggregation control.
  278. *
  279. * Preparation includes -
  280. * - Setting command ID, action and proper size
  281. * - Setting AMSDU control parameters (for SET only)
  282. * - Ensuring correct endian-ness
  283. */
  284. int mwifiex_cmd_amsdu_aggr_ctrl(struct mwifiex_private *priv,
  285. struct host_cmd_ds_command *cmd,
  286. int cmd_action, void *data_buf)
  287. {
  288. struct host_cmd_ds_amsdu_aggr_ctrl *amsdu_ctrl =
  289. &cmd->params.amsdu_aggr_ctrl;
  290. u16 action = (u16) cmd_action;
  291. struct mwifiex_ds_11n_amsdu_aggr_ctrl *aa_ctrl =
  292. (struct mwifiex_ds_11n_amsdu_aggr_ctrl *) data_buf;
  293. cmd->command = cpu_to_le16(HostCmd_CMD_AMSDU_AGGR_CTRL);
  294. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_amsdu_aggr_ctrl)
  295. + S_DS_GEN);
  296. amsdu_ctrl->action = cpu_to_le16(action);
  297. switch (action) {
  298. case HostCmd_ACT_GEN_SET:
  299. amsdu_ctrl->enable = cpu_to_le16(aa_ctrl->enable);
  300. amsdu_ctrl->curr_buf_size = 0;
  301. break;
  302. case HostCmd_ACT_GEN_GET:
  303. default:
  304. amsdu_ctrl->curr_buf_size = 0;
  305. break;
  306. }
  307. return 0;
  308. }
  309. /*
  310. * This function handles the command response of AMSDU aggregation
  311. * control request.
  312. *
  313. * Handling includes changing the header fields into CPU format.
  314. */
  315. int mwifiex_ret_amsdu_aggr_ctrl(struct mwifiex_private *priv,
  316. struct host_cmd_ds_command *resp,
  317. void *data_buf)
  318. {
  319. struct mwifiex_ds_11n_amsdu_aggr_ctrl *amsdu_aggr_ctrl = NULL;
  320. struct host_cmd_ds_amsdu_aggr_ctrl *amsdu_ctrl =
  321. &resp->params.amsdu_aggr_ctrl;
  322. if (data_buf) {
  323. amsdu_aggr_ctrl =
  324. (struct mwifiex_ds_11n_amsdu_aggr_ctrl *) data_buf;
  325. amsdu_aggr_ctrl->enable = le16_to_cpu(amsdu_ctrl->enable);
  326. amsdu_aggr_ctrl->curr_buf_size =
  327. le16_to_cpu(amsdu_ctrl->curr_buf_size);
  328. }
  329. return 0;
  330. }
  331. /*
  332. * This function prepares 11n configuration command.
  333. *
  334. * Preparation includes -
  335. * - Setting command ID, action and proper size
  336. * - Setting HT Tx capability and HT Tx information fields
  337. * - Ensuring correct endian-ness
  338. */
  339. int mwifiex_cmd_11n_cfg(struct mwifiex_private *priv,
  340. struct host_cmd_ds_command *cmd,
  341. u16 cmd_action, void *data_buf)
  342. {
  343. struct host_cmd_ds_11n_cfg *htcfg = &cmd->params.htcfg;
  344. struct mwifiex_ds_11n_tx_cfg *txcfg =
  345. (struct mwifiex_ds_11n_tx_cfg *) data_buf;
  346. cmd->command = cpu_to_le16(HostCmd_CMD_11N_CFG);
  347. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_11n_cfg) + S_DS_GEN);
  348. htcfg->action = cpu_to_le16(cmd_action);
  349. htcfg->ht_tx_cap = cpu_to_le16(txcfg->tx_htcap);
  350. htcfg->ht_tx_info = cpu_to_le16(txcfg->tx_htinfo);
  351. return 0;
  352. }
  353. /*
  354. * This function appends an 11n TLV to a buffer.
  355. *
  356. * Buffer allocation is responsibility of the calling
  357. * function. No size validation is made here.
  358. *
  359. * The function fills up the following sections, if applicable -
  360. * - HT capability IE
  361. * - HT information IE (with channel list)
  362. * - 20/40 BSS Coexistence IE
  363. * - HT Extended Capabilities IE
  364. */
  365. int
  366. mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv,
  367. struct mwifiex_bssdescriptor *bss_desc,
  368. u8 **buffer)
  369. {
  370. struct mwifiex_ie_types_htcap *ht_cap;
  371. struct mwifiex_ie_types_htinfo *ht_info;
  372. struct mwifiex_ie_types_chan_list_param_set *chan_list;
  373. struct mwifiex_ie_types_2040bssco *bss_co_2040;
  374. struct mwifiex_ie_types_extcap *ext_cap;
  375. int ret_len = 0;
  376. if (!buffer || !*buffer)
  377. return ret_len;
  378. if (bss_desc->bcn_ht_cap) {
  379. ht_cap = (struct mwifiex_ie_types_htcap *) *buffer;
  380. memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
  381. ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
  382. ht_cap->header.len =
  383. cpu_to_le16(sizeof(struct ieee80211_ht_cap));
  384. memcpy((u8 *) ht_cap + sizeof(struct mwifiex_ie_types_header),
  385. (u8 *) bss_desc->bcn_ht_cap +
  386. sizeof(struct ieee_types_header),
  387. le16_to_cpu(ht_cap->header.len));
  388. mwifiex_fill_cap_info(priv, ht_cap);
  389. *buffer += sizeof(struct mwifiex_ie_types_htcap);
  390. ret_len += sizeof(struct mwifiex_ie_types_htcap);
  391. }
  392. if (bss_desc->bcn_ht_info) {
  393. if (priv->bss_mode == MWIFIEX_BSS_MODE_IBSS) {
  394. ht_info = (struct mwifiex_ie_types_htinfo *) *buffer;
  395. memset(ht_info, 0,
  396. sizeof(struct mwifiex_ie_types_htinfo));
  397. ht_info->header.type =
  398. cpu_to_le16(WLAN_EID_HT_INFORMATION);
  399. ht_info->header.len =
  400. cpu_to_le16(sizeof(struct ieee80211_ht_info));
  401. memcpy((u8 *) ht_info +
  402. sizeof(struct mwifiex_ie_types_header),
  403. (u8 *) bss_desc->bcn_ht_info +
  404. sizeof(struct ieee_types_header),
  405. le16_to_cpu(ht_info->header.len));
  406. if (!ISSUPP_CHANWIDTH40
  407. (priv->adapter->hw_dot_11n_dev_cap)
  408. || !ISSUPP_CHANWIDTH40(priv->adapter->
  409. usr_dot_11n_dev_cap))
  410. RESET_CHANWIDTH40(ht_info->ht_info.ht_param);
  411. *buffer += sizeof(struct mwifiex_ie_types_htinfo);
  412. ret_len += sizeof(struct mwifiex_ie_types_htinfo);
  413. }
  414. chan_list =
  415. (struct mwifiex_ie_types_chan_list_param_set *) *buffer;
  416. memset(chan_list, 0,
  417. sizeof(struct mwifiex_ie_types_chan_list_param_set));
  418. chan_list->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  419. chan_list->header.len = cpu_to_le16(
  420. sizeof(struct mwifiex_ie_types_chan_list_param_set) -
  421. sizeof(struct mwifiex_ie_types_header));
  422. chan_list->chan_scan_param[0].chan_number =
  423. bss_desc->bcn_ht_info->control_chan;
  424. chan_list->chan_scan_param[0].radio_type =
  425. mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
  426. if ((ISSUPP_CHANWIDTH40(priv->adapter->hw_dot_11n_dev_cap) &&
  427. ISSUPP_CHANWIDTH40(priv->adapter->usr_dot_11n_dev_cap))
  428. && ISALLOWED_CHANWIDTH40(bss_desc->bcn_ht_info->ht_param))
  429. SET_SECONDARYCHAN(chan_list->chan_scan_param[0].
  430. radio_type,
  431. GET_SECONDARYCHAN(bss_desc->
  432. bcn_ht_info->ht_param));
  433. *buffer += sizeof(struct mwifiex_ie_types_chan_list_param_set);
  434. ret_len += sizeof(struct mwifiex_ie_types_chan_list_param_set);
  435. }
  436. if (bss_desc->bcn_bss_co_2040) {
  437. bss_co_2040 = (struct mwifiex_ie_types_2040bssco *) *buffer;
  438. memset(bss_co_2040, 0,
  439. sizeof(struct mwifiex_ie_types_2040bssco));
  440. bss_co_2040->header.type = cpu_to_le16(WLAN_EID_BSS_COEX_2040);
  441. bss_co_2040->header.len =
  442. cpu_to_le16(sizeof(bss_co_2040->bss_co_2040));
  443. memcpy((u8 *) bss_co_2040 +
  444. sizeof(struct mwifiex_ie_types_header),
  445. (u8 *) bss_desc->bcn_bss_co_2040 +
  446. sizeof(struct ieee_types_header),
  447. le16_to_cpu(bss_co_2040->header.len));
  448. *buffer += sizeof(struct mwifiex_ie_types_2040bssco);
  449. ret_len += sizeof(struct mwifiex_ie_types_2040bssco);
  450. }
  451. if (bss_desc->bcn_ext_cap) {
  452. ext_cap = (struct mwifiex_ie_types_extcap *) *buffer;
  453. memset(ext_cap, 0, sizeof(struct mwifiex_ie_types_extcap));
  454. ext_cap->header.type = cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
  455. ext_cap->header.len = cpu_to_le16(sizeof(ext_cap->ext_cap));
  456. memcpy((u8 *) ext_cap +
  457. sizeof(struct mwifiex_ie_types_header),
  458. (u8 *) bss_desc->bcn_ext_cap +
  459. sizeof(struct ieee_types_header),
  460. le16_to_cpu(ext_cap->header.len));
  461. *buffer += sizeof(struct mwifiex_ie_types_extcap);
  462. ret_len += sizeof(struct mwifiex_ie_types_extcap);
  463. }
  464. return ret_len;
  465. }
  466. /*
  467. * This function reconfigures the Tx buffer size in firmware.
  468. *
  469. * This function prepares a firmware command and issues it, if
  470. * the current Tx buffer size is different from the one requested.
  471. * Maximum configurable Tx buffer size is limited by the HT capability
  472. * field value.
  473. */
  474. void
  475. mwifiex_cfg_tx_buf(struct mwifiex_private *priv,
  476. struct mwifiex_bssdescriptor *bss_desc)
  477. {
  478. u16 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_2K;
  479. u16 tx_buf = 0;
  480. u16 curr_tx_buf_size = 0;
  481. if (bss_desc->bcn_ht_cap) {
  482. if (GETHT_MAXAMSDU(le16_to_cpu(bss_desc->bcn_ht_cap->cap_info)))
  483. max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_8K;
  484. else
  485. max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_4K;
  486. }
  487. tx_buf = min(priv->adapter->max_tx_buf_size, max_amsdu);
  488. dev_dbg(priv->adapter->dev, "info: max_amsdu=%d, max_tx_buf=%d\n",
  489. max_amsdu, priv->adapter->max_tx_buf_size);
  490. if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_2K)
  491. curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
  492. else if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_4K)
  493. curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K;
  494. else if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_8K)
  495. curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_8K;
  496. if (curr_tx_buf_size != tx_buf)
  497. mwifiex_prepare_cmd(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
  498. HostCmd_ACT_GEN_SET, 0,
  499. NULL, &tx_buf);
  500. return;
  501. }
  502. /*
  503. * This function checks if the given pointer is valid entry of
  504. * Tx BA Stream table.
  505. */
  506. static int mwifiex_is_tx_ba_stream_ptr_valid(struct mwifiex_private *priv,
  507. struct mwifiex_tx_ba_stream_tbl *tx_tbl_ptr)
  508. {
  509. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  510. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  511. if (tx_ba_tsr_tbl == tx_tbl_ptr)
  512. return true;
  513. }
  514. return false;
  515. }
  516. /*
  517. * This function deletes the given entry in Tx BA Stream table.
  518. *
  519. * The function also performs a validity check on the supplied
  520. * pointer before trying to delete.
  521. */
  522. void mwifiex_11n_delete_tx_ba_stream_tbl_entry(struct mwifiex_private *priv,
  523. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl)
  524. {
  525. if (!tx_ba_tsr_tbl &&
  526. mwifiex_is_tx_ba_stream_ptr_valid(priv, tx_ba_tsr_tbl))
  527. return;
  528. dev_dbg(priv->adapter->dev, "info: tx_ba_tsr_tbl %p\n", tx_ba_tsr_tbl);
  529. list_del(&tx_ba_tsr_tbl->list);
  530. kfree(tx_ba_tsr_tbl);
  531. return;
  532. }
  533. /*
  534. * This function deletes all the entries in Tx BA Stream table.
  535. */
  536. void mwifiex_11n_delete_all_tx_ba_stream_tbl(struct mwifiex_private *priv)
  537. {
  538. int i;
  539. struct mwifiex_tx_ba_stream_tbl *del_tbl_ptr, *tmp_node;
  540. unsigned long flags;
  541. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  542. list_for_each_entry_safe(del_tbl_ptr, tmp_node,
  543. &priv->tx_ba_stream_tbl_ptr, list)
  544. mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, del_tbl_ptr);
  545. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  546. INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
  547. for (i = 0; i < MAX_NUM_TID; ++i)
  548. priv->aggr_prio_tbl[i].ampdu_ap =
  549. priv->aggr_prio_tbl[i].ampdu_user;
  550. }
  551. /*
  552. * This function returns the pointer to an entry in BA Stream
  553. * table which matches the given RA/TID pair.
  554. */
  555. struct mwifiex_tx_ba_stream_tbl *
  556. mwifiex_11n_get_tx_ba_stream_tbl(struct mwifiex_private *priv,
  557. int tid, u8 *ra)
  558. {
  559. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  560. unsigned long flags;
  561. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  562. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  563. if ((!memcmp(tx_ba_tsr_tbl->ra, ra, ETH_ALEN))
  564. && (tx_ba_tsr_tbl->tid == tid)) {
  565. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
  566. flags);
  567. return tx_ba_tsr_tbl;
  568. }
  569. }
  570. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  571. return NULL;
  572. }
  573. /*
  574. * This function creates an entry in Tx BA stream table for the
  575. * given RA/TID pair.
  576. */
  577. void mwifiex_11n_create_tx_ba_stream_tbl(struct mwifiex_private *priv,
  578. u8 *ra, int tid,
  579. enum mwifiex_ba_status ba_status)
  580. {
  581. struct mwifiex_tx_ba_stream_tbl *new_node;
  582. unsigned long flags;
  583. if (!mwifiex_11n_get_tx_ba_stream_tbl(priv, tid, ra)) {
  584. new_node = kzalloc(sizeof(struct mwifiex_tx_ba_stream_tbl),
  585. GFP_ATOMIC);
  586. if (!new_node) {
  587. dev_err(priv->adapter->dev,
  588. "%s: failed to alloc new_node\n", __func__);
  589. return;
  590. }
  591. INIT_LIST_HEAD(&new_node->list);
  592. new_node->tid = tid;
  593. new_node->ba_status = ba_status;
  594. memcpy(new_node->ra, ra, ETH_ALEN);
  595. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  596. list_add_tail(&new_node->list, &priv->tx_ba_stream_tbl_ptr);
  597. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  598. }
  599. return;
  600. }
  601. /*
  602. * This function sends an add BA request to the given TID/RA pair.
  603. */
  604. int mwifiex_send_addba(struct mwifiex_private *priv, int tid, u8 *peer_mac)
  605. {
  606. struct host_cmd_ds_11n_addba_req add_ba_req;
  607. static u8 dialog_tok;
  608. int ret;
  609. dev_dbg(priv->adapter->dev, "cmd: %s: tid %d\n", __func__, tid);
  610. add_ba_req.block_ack_param_set = cpu_to_le16(
  611. (u16) ((tid << BLOCKACKPARAM_TID_POS) |
  612. (priv->add_ba_param.
  613. tx_win_size << BLOCKACKPARAM_WINSIZE_POS) |
  614. IMMEDIATE_BLOCK_ACK));
  615. add_ba_req.block_ack_tmo = cpu_to_le16((u16)priv->add_ba_param.timeout);
  616. ++dialog_tok;
  617. if (dialog_tok == 0)
  618. dialog_tok = 1;
  619. add_ba_req.dialog_token = dialog_tok;
  620. memcpy(&add_ba_req.peer_mac_addr, peer_mac, ETH_ALEN);
  621. /* We don't wait for the response of this command */
  622. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_11N_ADDBA_REQ,
  623. 0, 0, NULL, &add_ba_req);
  624. return ret;
  625. }
  626. /*
  627. * This function sends a delete BA request to the given TID/RA pair.
  628. */
  629. int mwifiex_send_delba(struct mwifiex_private *priv, int tid, u8 *peer_mac,
  630. int initiator)
  631. {
  632. struct host_cmd_ds_11n_delba delba;
  633. int ret;
  634. uint16_t del_ba_param_set;
  635. memset(&delba, 0, sizeof(delba));
  636. delba.del_ba_param_set = cpu_to_le16(tid << DELBA_TID_POS);
  637. del_ba_param_set = le16_to_cpu(delba.del_ba_param_set);
  638. if (initiator)
  639. del_ba_param_set |= IEEE80211_DELBA_PARAM_INITIATOR_MASK;
  640. else
  641. del_ba_param_set &= ~IEEE80211_DELBA_PARAM_INITIATOR_MASK;
  642. memcpy(&delba.peer_mac_addr, peer_mac, ETH_ALEN);
  643. /* We don't wait for the response of this command */
  644. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_11N_DELBA,
  645. HostCmd_ACT_GEN_SET, 0, NULL, &delba);
  646. return ret;
  647. }
  648. /*
  649. * This function handles the command response of a delete BA request.
  650. */
  651. void mwifiex_11n_delete_ba_stream(struct mwifiex_private *priv, u8 *del_ba)
  652. {
  653. struct host_cmd_ds_11n_delba *cmd_del_ba =
  654. (struct host_cmd_ds_11n_delba *) del_ba;
  655. uint16_t del_ba_param_set = le16_to_cpu(cmd_del_ba->del_ba_param_set);
  656. int tid;
  657. tid = del_ba_param_set >> DELBA_TID_POS;
  658. mwifiex_11n_delete_ba_stream_tbl(priv, tid, cmd_del_ba->peer_mac_addr,
  659. TYPE_DELBA_RECEIVE,
  660. INITIATOR_BIT(del_ba_param_set));
  661. }
  662. /*
  663. * This function retrieves the Rx reordering table.
  664. */
  665. int mwifiex_get_rx_reorder_tbl(struct mwifiex_private *priv,
  666. struct mwifiex_ds_rx_reorder_tbl *buf)
  667. {
  668. int i;
  669. struct mwifiex_ds_rx_reorder_tbl *rx_reo_tbl = buf;
  670. struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr;
  671. int count = 0;
  672. unsigned long flags;
  673. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  674. list_for_each_entry(rx_reorder_tbl_ptr, &priv->rx_reorder_tbl_ptr,
  675. list) {
  676. rx_reo_tbl->tid = (u16) rx_reorder_tbl_ptr->tid;
  677. memcpy(rx_reo_tbl->ta, rx_reorder_tbl_ptr->ta, ETH_ALEN);
  678. rx_reo_tbl->start_win = rx_reorder_tbl_ptr->start_win;
  679. rx_reo_tbl->win_size = rx_reorder_tbl_ptr->win_size;
  680. for (i = 0; i < rx_reorder_tbl_ptr->win_size; ++i) {
  681. if (rx_reorder_tbl_ptr->rx_reorder_ptr[i])
  682. rx_reo_tbl->buffer[i] = true;
  683. else
  684. rx_reo_tbl->buffer[i] = false;
  685. }
  686. rx_reo_tbl++;
  687. count++;
  688. if (count >= MWIFIEX_MAX_RX_BASTREAM_SUPPORTED)
  689. break;
  690. }
  691. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  692. return count;
  693. }
  694. /*
  695. * This function retrieves the Tx BA stream table.
  696. */
  697. int mwifiex_get_tx_ba_stream_tbl(struct mwifiex_private *priv,
  698. struct mwifiex_ds_tx_ba_stream_tbl *buf)
  699. {
  700. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  701. struct mwifiex_ds_tx_ba_stream_tbl *rx_reo_tbl = buf;
  702. int count = 0;
  703. unsigned long flags;
  704. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  705. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  706. rx_reo_tbl->tid = (u16) tx_ba_tsr_tbl->tid;
  707. dev_dbg(priv->adapter->dev, "data: %s tid=%d\n",
  708. __func__, rx_reo_tbl->tid);
  709. memcpy(rx_reo_tbl->ra, tx_ba_tsr_tbl->ra, ETH_ALEN);
  710. rx_reo_tbl++;
  711. count++;
  712. if (count >= MWIFIEX_MAX_TX_BASTREAM_SUPPORTED)
  713. break;
  714. }
  715. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  716. return count;
  717. }