11n.c 23 KB

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