11n.c 22 KB

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