11n.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  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. * Shows HT capability information fields.
  124. *
  125. * The following HT capability information fields are supported.
  126. * - Maximum AMSDU length (3839 bytes or 7935 bytes)
  127. * - Beam forming support
  128. * - Greenfield preamble support
  129. * - AMPDU support
  130. * - MIMO Power Save support
  131. * - Rx STBC support
  132. * - Tx STBC support
  133. * - Short GI for 20 MHz support
  134. * - Short GI for 40 MHz support
  135. * - LDPC coded packets receive support
  136. * - Number of delayed BA streams
  137. * - Number of immediate BA streams
  138. * - 10 MHz channel width support
  139. * - 20 MHz channel width support
  140. * - 40 MHz channel width support
  141. * - Presence of Tx antenna A/B/C/D
  142. * - Presence of Rx antenna A/B/C/D
  143. */
  144. void
  145. mwifiex_show_dot_11n_dev_cap(struct mwifiex_adapter *adapter, u32 cap)
  146. {
  147. dev_dbg(adapter->dev, "info: GET_HW_SPEC: Max MSDU len = %s octets\n",
  148. (ISSUPP_MAXAMSDU(cap) ? "7935" : "3839"));
  149. dev_dbg(adapter->dev, "info: GET_HW_SPEC: Beam forming %s\n",
  150. (ISSUPP_BEAMFORMING(cap) ? "supported" : "not supported"));
  151. dev_dbg(adapter->dev, "info: GET_HW_SPEC: Greenfield preamble %s\n",
  152. (ISSUPP_GREENFIELD(cap) ? "supported" : "not supported"));
  153. dev_dbg(adapter->dev, "info: GET_HW_SPEC: AMPDU %s\n",
  154. (ISSUPP_AMPDU(cap) ? "supported" : "not supported"));
  155. dev_dbg(adapter->dev, "info: GET_HW_SPEC: MIMO Power Save %s\n",
  156. (ISSUPP_MIMOPS(cap) ? "supported" : "not supported"));
  157. dev_dbg(adapter->dev, "info: GET_HW_SPEC: Rx STBC %s\n",
  158. (ISSUPP_RXSTBC(cap) ? "supported" : "not supported"));
  159. dev_dbg(adapter->dev, "info: GET_HW_SPEC: Tx STBC %s\n",
  160. (ISSUPP_TXSTBC(cap) ? "supported" : "not supported"));
  161. dev_dbg(adapter->dev, "info: GET_HW_SPEC: Short GI for 40 Mhz %s\n",
  162. (ISSUPP_SHORTGI40(cap) ? "supported" : "not supported"));
  163. dev_dbg(adapter->dev, "info: GET_HW_SPEC: Short GI for 20 Mhz %s\n",
  164. (ISSUPP_SHORTGI20(cap) ? "supported" : "not supported"));
  165. dev_dbg(adapter->dev, "info: GET_HW_SPEC: LDPC coded packet receive %s\n",
  166. (ISSUPP_RXLDPC(cap) ? "supported" : "not supported"));
  167. dev_dbg(adapter->dev,
  168. "info: GET_HW_SPEC: Number of Delayed Block Ack streams = %d\n",
  169. GET_DELAYEDBACK(cap));
  170. dev_dbg(adapter->dev,
  171. "info: GET_HW_SPEC: Number of Immediate Block Ack streams = %d\n",
  172. GET_IMMEDIATEBACK(cap));
  173. dev_dbg(adapter->dev, "info: GET_HW_SPEC: 40 Mhz channel width %s\n",
  174. (ISSUPP_CHANWIDTH40(cap) ? "supported" : "not supported"));
  175. dev_dbg(adapter->dev, "info: GET_HW_SPEC: 20 Mhz channel width %s\n",
  176. (ISSUPP_CHANWIDTH20(cap) ? "supported" : "not supported"));
  177. dev_dbg(adapter->dev, "info: GET_HW_SPEC: 10 Mhz channel width %s\n",
  178. (ISSUPP_CHANWIDTH10(cap) ? "supported" : "not supported"));
  179. if (ISSUPP_RXANTENNAA(cap))
  180. dev_dbg(adapter->dev, "info: GET_HW_SPEC: Prescence of Rx antennea A\n");
  181. if (ISSUPP_RXANTENNAB(cap))
  182. dev_dbg(adapter->dev, "info: GET_HW_SPEC: Prescence of Rx antennea B\n");
  183. if (ISSUPP_RXANTENNAC(cap))
  184. dev_dbg(adapter->dev, "info: GET_HW_SPEC: Prescence of Rx antennea C\n");
  185. if (ISSUPP_RXANTENNAD(cap))
  186. dev_dbg(adapter->dev, "info: GET_HW_SPEC: Prescence of Rx antennea D\n");
  187. if (ISSUPP_TXANTENNAA(cap))
  188. dev_dbg(adapter->dev, "info: GET_HW_SPEC: Prescence of Tx antennea A\n");
  189. if (ISSUPP_TXANTENNAB(cap))
  190. dev_dbg(adapter->dev, "info: GET_HW_SPEC: Prescence of Tx antennea B\n");
  191. if (ISSUPP_TXANTENNAC(cap))
  192. dev_dbg(adapter->dev, "info: GET_HW_SPEC: Prescence of Tx antennea C\n");
  193. if (ISSUPP_TXANTENNAD(cap))
  194. dev_dbg(adapter->dev, "info: GET_HW_SPEC: Prescence of Tx antennea D\n");
  195. return;
  196. }
  197. /*
  198. * Shows HT MCS support field.
  199. */
  200. void
  201. mwifiex_show_dev_mcs_support(struct mwifiex_adapter *adapter, u8 support)
  202. {
  203. dev_dbg(adapter->dev, "info: GET_HW_SPEC: MCSs for %dx%d MIMO\n",
  204. GET_RXMCSSUPP(support), GET_TXMCSSUPP(support));
  205. return;
  206. }
  207. /*
  208. * This function returns the pointer to an entry in BA Stream
  209. * table which matches the requested BA status.
  210. */
  211. static struct mwifiex_tx_ba_stream_tbl *
  212. mwifiex_11n_get_tx_ba_stream_status(struct mwifiex_private *priv,
  213. enum mwifiex_ba_status ba_status)
  214. {
  215. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  216. unsigned long flags;
  217. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  218. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  219. if (tx_ba_tsr_tbl->ba_status == ba_status) {
  220. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
  221. flags);
  222. return tx_ba_tsr_tbl;
  223. }
  224. }
  225. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  226. return NULL;
  227. }
  228. /*
  229. * This function handles the command response of delete a block
  230. * ack request.
  231. *
  232. * The function checks the response success status and takes action
  233. * accordingly (send an add BA request in case of success, or recreate
  234. * the deleted stream in case of failure, if the add BA was also
  235. * initiated by us).
  236. */
  237. int mwifiex_ret_11n_delba(struct mwifiex_private *priv,
  238. struct host_cmd_ds_command *resp)
  239. {
  240. int tid;
  241. struct mwifiex_tx_ba_stream_tbl *tx_ba_tbl;
  242. struct host_cmd_ds_11n_delba *del_ba =
  243. (struct host_cmd_ds_11n_delba *) &resp->params.del_ba;
  244. uint16_t del_ba_param_set = le16_to_cpu(del_ba->del_ba_param_set);
  245. tid = del_ba_param_set >> DELBA_TID_POS;
  246. if (del_ba->del_result == BA_RESULT_SUCCESS) {
  247. mwifiex_11n_delete_ba_stream_tbl(priv, tid,
  248. del_ba->peer_mac_addr, TYPE_DELBA_SENT,
  249. INITIATOR_BIT(del_ba_param_set));
  250. tx_ba_tbl = mwifiex_11n_get_tx_ba_stream_status(priv,
  251. BA_STREAM_SETUP_INPROGRESS);
  252. if (tx_ba_tbl)
  253. mwifiex_send_addba(priv, tx_ba_tbl->tid,
  254. tx_ba_tbl->ra);
  255. } else { /*
  256. * In case of failure, recreate the deleted stream in case
  257. * we initiated the ADDBA
  258. */
  259. if (INITIATOR_BIT(del_ba_param_set)) {
  260. mwifiex_11n_create_tx_ba_stream_tbl(priv,
  261. del_ba->peer_mac_addr, tid,
  262. BA_STREAM_SETUP_INPROGRESS);
  263. tx_ba_tbl = mwifiex_11n_get_tx_ba_stream_status(priv,
  264. BA_STREAM_SETUP_INPROGRESS);
  265. if (tx_ba_tbl)
  266. mwifiex_11n_delete_ba_stream_tbl(priv,
  267. tx_ba_tbl->tid, tx_ba_tbl->ra,
  268. TYPE_DELBA_SENT, true);
  269. }
  270. }
  271. return 0;
  272. }
  273. /*
  274. * This function handles the command response of add a block
  275. * ack request.
  276. *
  277. * Handling includes changing the header fields to CPU formats, checking
  278. * the response success status and taking actions accordingly (delete the
  279. * BA stream table in case of failure).
  280. */
  281. int mwifiex_ret_11n_addba_req(struct mwifiex_private *priv,
  282. struct host_cmd_ds_command *resp)
  283. {
  284. int tid;
  285. struct host_cmd_ds_11n_addba_rsp *add_ba_rsp =
  286. (struct host_cmd_ds_11n_addba_rsp *) &resp->params.add_ba_rsp;
  287. struct mwifiex_tx_ba_stream_tbl *tx_ba_tbl;
  288. add_ba_rsp->ssn = cpu_to_le16((le16_to_cpu(add_ba_rsp->ssn))
  289. & SSN_MASK);
  290. tid = (le16_to_cpu(add_ba_rsp->block_ack_param_set)
  291. & IEEE80211_ADDBA_PARAM_TID_MASK)
  292. >> BLOCKACKPARAM_TID_POS;
  293. if (le16_to_cpu(add_ba_rsp->status_code) == BA_RESULT_SUCCESS) {
  294. tx_ba_tbl = mwifiex_11n_get_tx_ba_stream_tbl(priv, tid,
  295. add_ba_rsp->peer_mac_addr);
  296. if (tx_ba_tbl) {
  297. dev_dbg(priv->adapter->dev, "info: BA stream complete\n");
  298. tx_ba_tbl->ba_status = BA_STREAM_SETUP_COMPLETE;
  299. } else {
  300. dev_err(priv->adapter->dev, "BA stream not created\n");
  301. }
  302. } else {
  303. mwifiex_11n_delete_ba_stream_tbl(priv, tid,
  304. add_ba_rsp->peer_mac_addr,
  305. TYPE_DELBA_SENT, true);
  306. if (add_ba_rsp->add_rsp_result != BA_RESULT_TIMEOUT)
  307. priv->aggr_prio_tbl[tid].ampdu_ap =
  308. BA_STREAM_NOT_ALLOWED;
  309. }
  310. return 0;
  311. }
  312. /*
  313. * This function handles the command response of 11n configuration request.
  314. *
  315. * Handling includes changing the header fields into CPU format.
  316. */
  317. int mwifiex_ret_11n_cfg(struct mwifiex_private *priv,
  318. struct host_cmd_ds_command *resp,
  319. void *data_buf)
  320. {
  321. struct mwifiex_ds_11n_tx_cfg *tx_cfg = NULL;
  322. struct host_cmd_ds_11n_cfg *htcfg = &resp->params.htcfg;
  323. if (data_buf) {
  324. tx_cfg = (struct mwifiex_ds_11n_tx_cfg *) data_buf;
  325. tx_cfg->tx_htcap = le16_to_cpu(htcfg->ht_tx_cap);
  326. tx_cfg->tx_htinfo = le16_to_cpu(htcfg->ht_tx_info);
  327. }
  328. return 0;
  329. }
  330. /*
  331. * This function prepares command of reconfigure Tx buffer.
  332. *
  333. * Preparation includes -
  334. * - Setting command ID, action and proper size
  335. * - Setting Tx buffer size (for SET only)
  336. * - Ensuring correct endian-ness
  337. */
  338. int mwifiex_cmd_recfg_tx_buf(struct mwifiex_private *priv,
  339. struct host_cmd_ds_command *cmd, int cmd_action,
  340. void *data_buf)
  341. {
  342. struct host_cmd_ds_txbuf_cfg *tx_buf = &cmd->params.tx_buf;
  343. u16 action = (u16) cmd_action;
  344. u16 buf_size = *((u16 *) data_buf);
  345. cmd->command = cpu_to_le16(HostCmd_CMD_RECONFIGURE_TX_BUFF);
  346. cmd->size =
  347. cpu_to_le16(sizeof(struct host_cmd_ds_txbuf_cfg) + S_DS_GEN);
  348. tx_buf->action = cpu_to_le16(action);
  349. switch (action) {
  350. case HostCmd_ACT_GEN_SET:
  351. dev_dbg(priv->adapter->dev, "cmd: set tx_buf=%d\n", buf_size);
  352. tx_buf->buff_size = cpu_to_le16(buf_size);
  353. break;
  354. case HostCmd_ACT_GEN_GET:
  355. default:
  356. tx_buf->buff_size = 0;
  357. break;
  358. }
  359. return 0;
  360. }
  361. /*
  362. * This function prepares command of AMSDU aggregation control.
  363. *
  364. * Preparation includes -
  365. * - Setting command ID, action and proper size
  366. * - Setting AMSDU control parameters (for SET only)
  367. * - Ensuring correct endian-ness
  368. */
  369. int mwifiex_cmd_amsdu_aggr_ctrl(struct mwifiex_private *priv,
  370. struct host_cmd_ds_command *cmd,
  371. int cmd_action, void *data_buf)
  372. {
  373. struct host_cmd_ds_amsdu_aggr_ctrl *amsdu_ctrl =
  374. &cmd->params.amsdu_aggr_ctrl;
  375. u16 action = (u16) cmd_action;
  376. struct mwifiex_ds_11n_amsdu_aggr_ctrl *aa_ctrl =
  377. (struct mwifiex_ds_11n_amsdu_aggr_ctrl *) data_buf;
  378. cmd->command = cpu_to_le16(HostCmd_CMD_AMSDU_AGGR_CTRL);
  379. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_amsdu_aggr_ctrl)
  380. + S_DS_GEN);
  381. amsdu_ctrl->action = cpu_to_le16(action);
  382. switch (action) {
  383. case HostCmd_ACT_GEN_SET:
  384. amsdu_ctrl->enable = cpu_to_le16(aa_ctrl->enable);
  385. amsdu_ctrl->curr_buf_size = 0;
  386. break;
  387. case HostCmd_ACT_GEN_GET:
  388. default:
  389. amsdu_ctrl->curr_buf_size = 0;
  390. break;
  391. }
  392. return 0;
  393. }
  394. /*
  395. * This function handles the command response of AMSDU aggregation
  396. * control request.
  397. *
  398. * Handling includes changing the header fields into CPU format.
  399. */
  400. int mwifiex_ret_amsdu_aggr_ctrl(struct mwifiex_private *priv,
  401. struct host_cmd_ds_command *resp,
  402. void *data_buf)
  403. {
  404. struct mwifiex_ds_11n_amsdu_aggr_ctrl *amsdu_aggr_ctrl = NULL;
  405. struct host_cmd_ds_amsdu_aggr_ctrl *amsdu_ctrl =
  406. &resp->params.amsdu_aggr_ctrl;
  407. if (data_buf) {
  408. amsdu_aggr_ctrl =
  409. (struct mwifiex_ds_11n_amsdu_aggr_ctrl *) data_buf;
  410. amsdu_aggr_ctrl->enable = le16_to_cpu(amsdu_ctrl->enable);
  411. amsdu_aggr_ctrl->curr_buf_size =
  412. le16_to_cpu(amsdu_ctrl->curr_buf_size);
  413. }
  414. return 0;
  415. }
  416. /*
  417. * This function prepares 11n configuration command.
  418. *
  419. * Preparation includes -
  420. * - Setting command ID, action and proper size
  421. * - Setting HT Tx capability and HT Tx information fields
  422. * - Ensuring correct endian-ness
  423. */
  424. int mwifiex_cmd_11n_cfg(struct mwifiex_private *priv,
  425. struct host_cmd_ds_command *cmd,
  426. u16 cmd_action, void *data_buf)
  427. {
  428. struct host_cmd_ds_11n_cfg *htcfg = &cmd->params.htcfg;
  429. struct mwifiex_ds_11n_tx_cfg *txcfg =
  430. (struct mwifiex_ds_11n_tx_cfg *) data_buf;
  431. cmd->command = cpu_to_le16(HostCmd_CMD_11N_CFG);
  432. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_11n_cfg) + S_DS_GEN);
  433. htcfg->action = cpu_to_le16(cmd_action);
  434. htcfg->ht_tx_cap = cpu_to_le16(txcfg->tx_htcap);
  435. htcfg->ht_tx_info = cpu_to_le16(txcfg->tx_htinfo);
  436. return 0;
  437. }
  438. /*
  439. * This function appends an 11n TLV to a buffer.
  440. *
  441. * Buffer allocation is responsibility of the calling
  442. * function. No size validation is made here.
  443. *
  444. * The function fills up the following sections, if applicable -
  445. * - HT capability IE
  446. * - HT information IE (with channel list)
  447. * - 20/40 BSS Coexistence IE
  448. * - HT Extended Capabilities IE
  449. */
  450. int
  451. mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv,
  452. struct mwifiex_bssdescriptor *bss_desc,
  453. u8 **buffer)
  454. {
  455. struct mwifiex_ie_types_htcap *ht_cap;
  456. struct mwifiex_ie_types_htinfo *ht_info;
  457. struct mwifiex_ie_types_chan_list_param_set *chan_list;
  458. struct mwifiex_ie_types_2040bssco *bss_co_2040;
  459. struct mwifiex_ie_types_extcap *ext_cap;
  460. int ret_len = 0;
  461. if (!buffer || !*buffer)
  462. return ret_len;
  463. if (bss_desc->bcn_ht_cap) {
  464. ht_cap = (struct mwifiex_ie_types_htcap *) *buffer;
  465. memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
  466. ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
  467. ht_cap->header.len =
  468. cpu_to_le16(sizeof(struct ieee80211_ht_cap));
  469. memcpy((u8 *) ht_cap + sizeof(struct mwifiex_ie_types_header),
  470. (u8 *) bss_desc->bcn_ht_cap +
  471. sizeof(struct ieee_types_header),
  472. le16_to_cpu(ht_cap->header.len));
  473. mwifiex_fill_cap_info(priv, ht_cap);
  474. *buffer += sizeof(struct mwifiex_ie_types_htcap);
  475. ret_len += sizeof(struct mwifiex_ie_types_htcap);
  476. }
  477. if (bss_desc->bcn_ht_info) {
  478. if (priv->bss_mode == MWIFIEX_BSS_MODE_IBSS) {
  479. ht_info = (struct mwifiex_ie_types_htinfo *) *buffer;
  480. memset(ht_info, 0,
  481. sizeof(struct mwifiex_ie_types_htinfo));
  482. ht_info->header.type =
  483. cpu_to_le16(WLAN_EID_HT_INFORMATION);
  484. ht_info->header.len =
  485. cpu_to_le16(sizeof(struct ieee80211_ht_info));
  486. memcpy((u8 *) ht_info +
  487. sizeof(struct mwifiex_ie_types_header),
  488. (u8 *) bss_desc->bcn_ht_info +
  489. sizeof(struct ieee_types_header),
  490. le16_to_cpu(ht_info->header.len));
  491. if (!ISSUPP_CHANWIDTH40
  492. (priv->adapter->hw_dot_11n_dev_cap)
  493. || !ISSUPP_CHANWIDTH40(priv->adapter->
  494. usr_dot_11n_dev_cap))
  495. RESET_CHANWIDTH40(ht_info->ht_info.ht_param);
  496. *buffer += sizeof(struct mwifiex_ie_types_htinfo);
  497. ret_len += sizeof(struct mwifiex_ie_types_htinfo);
  498. }
  499. chan_list =
  500. (struct mwifiex_ie_types_chan_list_param_set *) *buffer;
  501. memset(chan_list, 0,
  502. sizeof(struct mwifiex_ie_types_chan_list_param_set));
  503. chan_list->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  504. chan_list->header.len = cpu_to_le16(
  505. sizeof(struct mwifiex_ie_types_chan_list_param_set) -
  506. sizeof(struct mwifiex_ie_types_header));
  507. chan_list->chan_scan_param[0].chan_number =
  508. bss_desc->bcn_ht_info->control_chan;
  509. chan_list->chan_scan_param[0].radio_type =
  510. mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
  511. if ((ISSUPP_CHANWIDTH40(priv->adapter->hw_dot_11n_dev_cap) &&
  512. ISSUPP_CHANWIDTH40(priv->adapter->usr_dot_11n_dev_cap))
  513. && ISALLOWED_CHANWIDTH40(bss_desc->bcn_ht_info->ht_param))
  514. SET_SECONDARYCHAN(chan_list->chan_scan_param[0].
  515. radio_type,
  516. GET_SECONDARYCHAN(bss_desc->
  517. bcn_ht_info->ht_param));
  518. *buffer += sizeof(struct mwifiex_ie_types_chan_list_param_set);
  519. ret_len += sizeof(struct mwifiex_ie_types_chan_list_param_set);
  520. }
  521. if (bss_desc->bcn_bss_co_2040) {
  522. bss_co_2040 = (struct mwifiex_ie_types_2040bssco *) *buffer;
  523. memset(bss_co_2040, 0,
  524. sizeof(struct mwifiex_ie_types_2040bssco));
  525. bss_co_2040->header.type = cpu_to_le16(WLAN_EID_BSS_COEX_2040);
  526. bss_co_2040->header.len =
  527. cpu_to_le16(sizeof(bss_co_2040->bss_co_2040));
  528. memcpy((u8 *) bss_co_2040 +
  529. sizeof(struct mwifiex_ie_types_header),
  530. (u8 *) bss_desc->bcn_bss_co_2040 +
  531. sizeof(struct ieee_types_header),
  532. le16_to_cpu(bss_co_2040->header.len));
  533. *buffer += sizeof(struct mwifiex_ie_types_2040bssco);
  534. ret_len += sizeof(struct mwifiex_ie_types_2040bssco);
  535. }
  536. if (bss_desc->bcn_ext_cap) {
  537. ext_cap = (struct mwifiex_ie_types_extcap *) *buffer;
  538. memset(ext_cap, 0, sizeof(struct mwifiex_ie_types_extcap));
  539. ext_cap->header.type = cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
  540. ext_cap->header.len = cpu_to_le16(sizeof(ext_cap->ext_cap));
  541. memcpy((u8 *) ext_cap +
  542. sizeof(struct mwifiex_ie_types_header),
  543. (u8 *) bss_desc->bcn_ext_cap +
  544. sizeof(struct ieee_types_header),
  545. le16_to_cpu(ext_cap->header.len));
  546. *buffer += sizeof(struct mwifiex_ie_types_extcap);
  547. ret_len += sizeof(struct mwifiex_ie_types_extcap);
  548. }
  549. return ret_len;
  550. }
  551. /*
  552. * This function reconfigures the Tx buffer size in firmware.
  553. *
  554. * This function prepares a firmware command and issues it, if
  555. * the current Tx buffer size is different from the one requested.
  556. * Maximum configurable Tx buffer size is limited by the HT capability
  557. * field value.
  558. */
  559. void
  560. mwifiex_cfg_tx_buf(struct mwifiex_private *priv,
  561. struct mwifiex_bssdescriptor *bss_desc)
  562. {
  563. u16 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_2K;
  564. u16 tx_buf = 0;
  565. u16 curr_tx_buf_size = 0;
  566. if (bss_desc->bcn_ht_cap) {
  567. if (GETHT_MAXAMSDU(le16_to_cpu(bss_desc->bcn_ht_cap->cap_info)))
  568. max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_8K;
  569. else
  570. max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_4K;
  571. }
  572. tx_buf = min(priv->adapter->max_tx_buf_size, max_amsdu);
  573. dev_dbg(priv->adapter->dev, "info: max_amsdu=%d, max_tx_buf=%d\n",
  574. max_amsdu, priv->adapter->max_tx_buf_size);
  575. if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_2K)
  576. curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
  577. else if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_4K)
  578. curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K;
  579. else if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_8K)
  580. curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_8K;
  581. if (curr_tx_buf_size != tx_buf)
  582. mwifiex_prepare_cmd(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
  583. HostCmd_ACT_GEN_SET, 0,
  584. NULL, &tx_buf);
  585. return;
  586. }
  587. /*
  588. * This function checks if the given pointer is valid entry of
  589. * Tx BA Stream table.
  590. */
  591. static int mwifiex_is_tx_ba_stream_ptr_valid(struct mwifiex_private *priv,
  592. struct mwifiex_tx_ba_stream_tbl *tx_tbl_ptr)
  593. {
  594. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  595. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  596. if (tx_ba_tsr_tbl == tx_tbl_ptr)
  597. return true;
  598. }
  599. return false;
  600. }
  601. /*
  602. * This function deletes the given entry in Tx BA Stream table.
  603. *
  604. * The function also performs a validity check on the supplied
  605. * pointer before trying to delete.
  606. */
  607. void mwifiex_11n_delete_tx_ba_stream_tbl_entry(struct mwifiex_private *priv,
  608. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl)
  609. {
  610. if (!tx_ba_tsr_tbl &&
  611. mwifiex_is_tx_ba_stream_ptr_valid(priv, tx_ba_tsr_tbl))
  612. return;
  613. dev_dbg(priv->adapter->dev, "info: tx_ba_tsr_tbl %p\n", tx_ba_tsr_tbl);
  614. list_del(&tx_ba_tsr_tbl->list);
  615. kfree(tx_ba_tsr_tbl);
  616. return;
  617. }
  618. /*
  619. * This function deletes all the entries in Tx BA Stream table.
  620. */
  621. void mwifiex_11n_delete_all_tx_ba_stream_tbl(struct mwifiex_private *priv)
  622. {
  623. int i;
  624. struct mwifiex_tx_ba_stream_tbl *del_tbl_ptr, *tmp_node;
  625. unsigned long flags;
  626. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  627. list_for_each_entry_safe(del_tbl_ptr, tmp_node,
  628. &priv->tx_ba_stream_tbl_ptr, list)
  629. mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, del_tbl_ptr);
  630. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  631. INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
  632. for (i = 0; i < MAX_NUM_TID; ++i)
  633. priv->aggr_prio_tbl[i].ampdu_ap =
  634. priv->aggr_prio_tbl[i].ampdu_user;
  635. }
  636. /*
  637. * This function returns the pointer to an entry in BA Stream
  638. * table which matches the given RA/TID pair.
  639. */
  640. struct mwifiex_tx_ba_stream_tbl *
  641. mwifiex_11n_get_tx_ba_stream_tbl(struct mwifiex_private *priv,
  642. int tid, u8 *ra)
  643. {
  644. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  645. unsigned long flags;
  646. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  647. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  648. if ((!memcmp(tx_ba_tsr_tbl->ra, ra, ETH_ALEN))
  649. && (tx_ba_tsr_tbl->tid == tid)) {
  650. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
  651. flags);
  652. return tx_ba_tsr_tbl;
  653. }
  654. }
  655. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  656. return NULL;
  657. }
  658. /*
  659. * This function creates an entry in Tx BA stream table for the
  660. * given RA/TID pair.
  661. */
  662. void mwifiex_11n_create_tx_ba_stream_tbl(struct mwifiex_private *priv,
  663. u8 *ra, int tid,
  664. enum mwifiex_ba_status ba_status)
  665. {
  666. struct mwifiex_tx_ba_stream_tbl *new_node;
  667. unsigned long flags;
  668. if (!mwifiex_11n_get_tx_ba_stream_tbl(priv, tid, ra)) {
  669. new_node = kzalloc(sizeof(struct mwifiex_tx_ba_stream_tbl),
  670. GFP_ATOMIC);
  671. if (!new_node) {
  672. dev_err(priv->adapter->dev,
  673. "%s: failed to alloc new_node\n", __func__);
  674. return;
  675. }
  676. INIT_LIST_HEAD(&new_node->list);
  677. new_node->tid = tid;
  678. new_node->ba_status = ba_status;
  679. memcpy(new_node->ra, ra, ETH_ALEN);
  680. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  681. list_add_tail(&new_node->list, &priv->tx_ba_stream_tbl_ptr);
  682. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  683. }
  684. return;
  685. }
  686. /*
  687. * This function sends an add BA request to the given TID/RA pair.
  688. */
  689. int mwifiex_send_addba(struct mwifiex_private *priv, int tid, u8 *peer_mac)
  690. {
  691. struct host_cmd_ds_11n_addba_req add_ba_req;
  692. static u8 dialog_tok;
  693. int ret;
  694. dev_dbg(priv->adapter->dev, "cmd: %s: tid %d\n", __func__, tid);
  695. add_ba_req.block_ack_param_set = cpu_to_le16(
  696. (u16) ((tid << BLOCKACKPARAM_TID_POS) |
  697. (priv->add_ba_param.
  698. tx_win_size << BLOCKACKPARAM_WINSIZE_POS) |
  699. IMMEDIATE_BLOCK_ACK));
  700. add_ba_req.block_ack_tmo = cpu_to_le16((u16)priv->add_ba_param.timeout);
  701. ++dialog_tok;
  702. if (dialog_tok == 0)
  703. dialog_tok = 1;
  704. add_ba_req.dialog_token = dialog_tok;
  705. memcpy(&add_ba_req.peer_mac_addr, peer_mac, ETH_ALEN);
  706. /* We don't wait for the response of this command */
  707. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_11N_ADDBA_REQ,
  708. 0, 0, NULL, &add_ba_req);
  709. return ret;
  710. }
  711. /*
  712. * This function sends a delete BA request to the given TID/RA pair.
  713. */
  714. int mwifiex_send_delba(struct mwifiex_private *priv, int tid, u8 *peer_mac,
  715. int initiator)
  716. {
  717. struct host_cmd_ds_11n_delba delba;
  718. int ret;
  719. uint16_t del_ba_param_set;
  720. memset(&delba, 0, sizeof(delba));
  721. delba.del_ba_param_set = cpu_to_le16(tid << DELBA_TID_POS);
  722. del_ba_param_set = le16_to_cpu(delba.del_ba_param_set);
  723. if (initiator)
  724. del_ba_param_set |= IEEE80211_DELBA_PARAM_INITIATOR_MASK;
  725. else
  726. del_ba_param_set &= ~IEEE80211_DELBA_PARAM_INITIATOR_MASK;
  727. memcpy(&delba.peer_mac_addr, peer_mac, ETH_ALEN);
  728. /* We don't wait for the response of this command */
  729. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_11N_DELBA,
  730. HostCmd_ACT_GEN_SET, 0, NULL, &delba);
  731. return ret;
  732. }
  733. /*
  734. * This function handles the command response of a delete BA request.
  735. */
  736. void mwifiex_11n_delete_ba_stream(struct mwifiex_private *priv, u8 *del_ba)
  737. {
  738. struct host_cmd_ds_11n_delba *cmd_del_ba =
  739. (struct host_cmd_ds_11n_delba *) del_ba;
  740. uint16_t del_ba_param_set = le16_to_cpu(cmd_del_ba->del_ba_param_set);
  741. int tid;
  742. tid = del_ba_param_set >> DELBA_TID_POS;
  743. mwifiex_11n_delete_ba_stream_tbl(priv, tid, cmd_del_ba->peer_mac_addr,
  744. TYPE_DELBA_RECEIVE,
  745. INITIATOR_BIT(del_ba_param_set));
  746. }
  747. /*
  748. * This function retrieves the Rx reordering table.
  749. */
  750. int mwifiex_get_rx_reorder_tbl(struct mwifiex_private *priv,
  751. struct mwifiex_ds_rx_reorder_tbl *buf)
  752. {
  753. int i;
  754. struct mwifiex_ds_rx_reorder_tbl *rx_reo_tbl = buf;
  755. struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr;
  756. int count = 0;
  757. unsigned long flags;
  758. spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
  759. list_for_each_entry(rx_reorder_tbl_ptr, &priv->rx_reorder_tbl_ptr,
  760. list) {
  761. rx_reo_tbl->tid = (u16) rx_reorder_tbl_ptr->tid;
  762. memcpy(rx_reo_tbl->ta, rx_reorder_tbl_ptr->ta, ETH_ALEN);
  763. rx_reo_tbl->start_win = rx_reorder_tbl_ptr->start_win;
  764. rx_reo_tbl->win_size = rx_reorder_tbl_ptr->win_size;
  765. for (i = 0; i < rx_reorder_tbl_ptr->win_size; ++i) {
  766. if (rx_reorder_tbl_ptr->rx_reorder_ptr[i])
  767. rx_reo_tbl->buffer[i] = true;
  768. else
  769. rx_reo_tbl->buffer[i] = false;
  770. }
  771. rx_reo_tbl++;
  772. count++;
  773. if (count >= MWIFIEX_MAX_RX_BASTREAM_SUPPORTED)
  774. break;
  775. }
  776. spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
  777. return count;
  778. }
  779. /*
  780. * This function retrieves the Tx BA stream table.
  781. */
  782. int mwifiex_get_tx_ba_stream_tbl(struct mwifiex_private *priv,
  783. struct mwifiex_ds_tx_ba_stream_tbl *buf)
  784. {
  785. struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
  786. struct mwifiex_ds_tx_ba_stream_tbl *rx_reo_tbl = buf;
  787. int count = 0;
  788. unsigned long flags;
  789. spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
  790. list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
  791. rx_reo_tbl->tid = (u16) tx_ba_tsr_tbl->tid;
  792. dev_dbg(priv->adapter->dev, "data: %s tid=%d\n",
  793. __func__, rx_reo_tbl->tid);
  794. memcpy(rx_reo_tbl->ra, tx_ba_tsr_tbl->ra, ETH_ALEN);
  795. rx_reo_tbl++;
  796. count++;
  797. if (count >= MWIFIEX_MAX_TX_BASTREAM_SUPPORTED)
  798. break;
  799. }
  800. spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
  801. return count;
  802. }