11n.c 24 KB

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