11ac.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * NXP Wireless LAN device driver: 802.11ac
  4. *
  5. * Copyright 2011-2020 NXP
  6. */
  7. #include "decl.h"
  8. #include "ioctl.h"
  9. #include "fw.h"
  10. #include "main.h"
  11. #include "11ac.h"
  12. /* Tables of the MCS map to the highest data rate (in Mbps) supported
  13. * for long GI.
  14. */
  15. static const u16 max_rate_lgi_80MHZ[8][3] = {
  16. {0x124, 0x15F, 0x186}, /* NSS = 1 */
  17. {0x249, 0x2BE, 0x30C}, /* NSS = 2 */
  18. {0x36D, 0x41D, 0x492}, /* NSS = 3 */
  19. {0x492, 0x57C, 0x618}, /* NSS = 4 */
  20. {0x5B6, 0x6DB, 0x79E}, /* NSS = 5 */
  21. {0x6DB, 0x83A, 0x0}, /* NSS = 6 */
  22. {0x7FF, 0x999, 0xAAA}, /* NSS = 7 */
  23. {0x924, 0xAF8, 0xC30} /* NSS = 8 */
  24. };
  25. static const u16 max_rate_lgi_160MHZ[8][3] = {
  26. {0x249, 0x2BE, 0x30C}, /* NSS = 1 */
  27. {0x492, 0x57C, 0x618}, /* NSS = 2 */
  28. {0x6DB, 0x83A, 0x0}, /* NSS = 3 */
  29. {0x924, 0xAF8, 0xC30}, /* NSS = 4 */
  30. {0xB6D, 0xDB6, 0xF3C}, /* NSS = 5 */
  31. {0xDB6, 0x1074, 0x1248}, /* NSS = 6 */
  32. {0xFFF, 0x1332, 0x1554}, /* NSS = 7 */
  33. {0x1248, 0x15F0, 0x1860} /* NSS = 8 */
  34. };
  35. /* This function converts the 2-bit MCS map to the highest long GI
  36. * VHT data rate.
  37. */
  38. static u16
  39. mwifiex_convert_mcsmap_to_maxrate(struct mwifiex_private *priv,
  40. u8 bands, u16 mcs_map)
  41. {
  42. u8 i, nss, mcs;
  43. u16 max_rate = 0;
  44. u32 usr_vht_cap_info = 0;
  45. struct mwifiex_adapter *adapter = priv->adapter;
  46. if (bands & BAND_AAC)
  47. usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_a;
  48. else
  49. usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_bg;
  50. /* find the max NSS supported */
  51. nss = 1;
  52. for (i = 1; i <= 8; i++) {
  53. mcs = GET_VHTNSSMCS(mcs_map, i);
  54. if (mcs < IEEE80211_VHT_MCS_NOT_SUPPORTED)
  55. nss = i;
  56. }
  57. mcs = GET_VHTNSSMCS(mcs_map, nss);
  58. /* if mcs is 3, nss must be 1 (NSS = 1). Default mcs to MCS 0~9 */
  59. if (mcs == IEEE80211_VHT_MCS_NOT_SUPPORTED)
  60. mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
  61. if (GET_VHTCAP_CHWDSET(usr_vht_cap_info)) {
  62. /* support 160 MHz */
  63. max_rate = max_rate_lgi_160MHZ[nss - 1][mcs];
  64. if (!max_rate)
  65. /* MCS9 is not supported in NSS6 */
  66. max_rate = max_rate_lgi_160MHZ[nss - 1][mcs - 1];
  67. } else {
  68. max_rate = max_rate_lgi_80MHZ[nss - 1][mcs];
  69. if (!max_rate)
  70. /* MCS9 is not supported in NSS3 */
  71. max_rate = max_rate_lgi_80MHZ[nss - 1][mcs - 1];
  72. }
  73. return max_rate;
  74. }
  75. static void
  76. mwifiex_fill_vht_cap_info(struct mwifiex_private *priv,
  77. struct ieee80211_vht_cap *vht_cap, u8 bands)
  78. {
  79. struct mwifiex_adapter *adapter = priv->adapter;
  80. if (bands & BAND_A)
  81. vht_cap->vht_cap_info =
  82. cpu_to_le32(adapter->usr_dot_11ac_dev_cap_a);
  83. else
  84. vht_cap->vht_cap_info =
  85. cpu_to_le32(adapter->usr_dot_11ac_dev_cap_bg);
  86. }
  87. void mwifiex_fill_vht_cap_tlv(struct mwifiex_private *priv,
  88. struct ieee80211_vht_cap *vht_cap, u8 bands)
  89. {
  90. struct mwifiex_adapter *adapter = priv->adapter;
  91. u16 mcs_map_user, mcs_map_resp, mcs_map_result;
  92. u16 mcs_user, mcs_resp, nss, tmp;
  93. /* Fill VHT cap info */
  94. mwifiex_fill_vht_cap_info(priv, vht_cap, bands);
  95. /* rx MCS Set: find the minimum of the user rx mcs and ap rx mcs */
  96. mcs_map_user = GET_DEVRXMCSMAP(adapter->usr_dot_11ac_mcs_support);
  97. mcs_map_resp = le16_to_cpu(vht_cap->supp_mcs.rx_mcs_map);
  98. mcs_map_result = 0;
  99. for (nss = 1; nss <= 8; nss++) {
  100. mcs_user = GET_VHTNSSMCS(mcs_map_user, nss);
  101. mcs_resp = GET_VHTNSSMCS(mcs_map_resp, nss);
  102. if ((mcs_user == IEEE80211_VHT_MCS_NOT_SUPPORTED) ||
  103. (mcs_resp == IEEE80211_VHT_MCS_NOT_SUPPORTED))
  104. SET_VHTNSSMCS(mcs_map_result, nss,
  105. IEEE80211_VHT_MCS_NOT_SUPPORTED);
  106. else
  107. SET_VHTNSSMCS(mcs_map_result, nss,
  108. min(mcs_user, mcs_resp));
  109. }
  110. vht_cap->supp_mcs.rx_mcs_map = cpu_to_le16(mcs_map_result);
  111. tmp = mwifiex_convert_mcsmap_to_maxrate(priv, bands, mcs_map_result);
  112. vht_cap->supp_mcs.rx_highest = cpu_to_le16(tmp);
  113. /* tx MCS Set: find the minimum of the user tx mcs and ap tx mcs */
  114. mcs_map_user = GET_DEVTXMCSMAP(adapter->usr_dot_11ac_mcs_support);
  115. mcs_map_resp = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
  116. mcs_map_result = 0;
  117. for (nss = 1; nss <= 8; nss++) {
  118. mcs_user = GET_VHTNSSMCS(mcs_map_user, nss);
  119. mcs_resp = GET_VHTNSSMCS(mcs_map_resp, nss);
  120. if ((mcs_user == IEEE80211_VHT_MCS_NOT_SUPPORTED) ||
  121. (mcs_resp == IEEE80211_VHT_MCS_NOT_SUPPORTED))
  122. SET_VHTNSSMCS(mcs_map_result, nss,
  123. IEEE80211_VHT_MCS_NOT_SUPPORTED);
  124. else
  125. SET_VHTNSSMCS(mcs_map_result, nss,
  126. min(mcs_user, mcs_resp));
  127. }
  128. vht_cap->supp_mcs.tx_mcs_map = cpu_to_le16(mcs_map_result);
  129. tmp = mwifiex_convert_mcsmap_to_maxrate(priv, bands, mcs_map_result);
  130. vht_cap->supp_mcs.tx_highest = cpu_to_le16(tmp);
  131. return;
  132. }
  133. int mwifiex_cmd_append_11ac_tlv(struct mwifiex_private *priv,
  134. struct mwifiex_bssdescriptor *bss_desc,
  135. u8 **buffer)
  136. {
  137. struct mwifiex_ie_types_vhtcap *vht_cap;
  138. struct mwifiex_ie_types_oper_mode_ntf *oper_ntf;
  139. struct ieee_types_oper_mode_ntf *ieee_oper_ntf;
  140. struct mwifiex_ie_types_vht_oper *vht_op;
  141. struct mwifiex_adapter *adapter = priv->adapter;
  142. u8 supp_chwd_set;
  143. u32 usr_vht_cap_info;
  144. int ret_len = 0;
  145. if (bss_desc->bss_band & BAND_A)
  146. usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_a;
  147. else
  148. usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_bg;
  149. /* VHT Capabilities IE */
  150. if (bss_desc->bcn_vht_cap) {
  151. vht_cap = (struct mwifiex_ie_types_vhtcap *)*buffer;
  152. memset(vht_cap, 0, sizeof(*vht_cap));
  153. vht_cap->header.type = cpu_to_le16(WLAN_EID_VHT_CAPABILITY);
  154. vht_cap->header.len =
  155. cpu_to_le16(sizeof(struct ieee80211_vht_cap));
  156. memcpy((u8 *)vht_cap + sizeof(struct mwifiex_ie_types_header),
  157. (u8 *)bss_desc->bcn_vht_cap,
  158. le16_to_cpu(vht_cap->header.len));
  159. mwifiex_fill_vht_cap_tlv(priv, &vht_cap->vht_cap,
  160. bss_desc->bss_band);
  161. *buffer += sizeof(*vht_cap);
  162. ret_len += sizeof(*vht_cap);
  163. }
  164. /* VHT Operation IE */
  165. if (bss_desc->bcn_vht_oper) {
  166. if (priv->bss_mode == NL80211_IFTYPE_STATION) {
  167. vht_op = (struct mwifiex_ie_types_vht_oper *)*buffer;
  168. memset(vht_op, 0, sizeof(*vht_op));
  169. vht_op->header.type =
  170. cpu_to_le16(WLAN_EID_VHT_OPERATION);
  171. vht_op->header.len = cpu_to_le16(sizeof(*vht_op) -
  172. sizeof(struct mwifiex_ie_types_header));
  173. memcpy((u8 *)vht_op +
  174. sizeof(struct mwifiex_ie_types_header),
  175. (u8 *)bss_desc->bcn_vht_oper,
  176. le16_to_cpu(vht_op->header.len));
  177. /* negotiate the channel width and central freq
  178. * and keep the central freq as the peer suggests
  179. */
  180. supp_chwd_set = GET_VHTCAP_CHWDSET(usr_vht_cap_info);
  181. switch (supp_chwd_set) {
  182. case 0:
  183. vht_op->chan_width =
  184. min_t(u8, IEEE80211_VHT_CHANWIDTH_80MHZ,
  185. bss_desc->bcn_vht_oper->chan_width);
  186. break;
  187. case 1:
  188. vht_op->chan_width =
  189. min_t(u8, IEEE80211_VHT_CHANWIDTH_160MHZ,
  190. bss_desc->bcn_vht_oper->chan_width);
  191. break;
  192. case 2:
  193. vht_op->chan_width =
  194. min_t(u8, IEEE80211_VHT_CHANWIDTH_80P80MHZ,
  195. bss_desc->bcn_vht_oper->chan_width);
  196. break;
  197. default:
  198. vht_op->chan_width =
  199. IEEE80211_VHT_CHANWIDTH_USE_HT;
  200. break;
  201. }
  202. *buffer += sizeof(*vht_op);
  203. ret_len += sizeof(*vht_op);
  204. }
  205. }
  206. /* Operating Mode Notification IE */
  207. if (bss_desc->oper_mode) {
  208. ieee_oper_ntf = bss_desc->oper_mode;
  209. oper_ntf = (void *)*buffer;
  210. memset(oper_ntf, 0, sizeof(*oper_ntf));
  211. oper_ntf->header.type = cpu_to_le16(WLAN_EID_OPMODE_NOTIF);
  212. oper_ntf->header.len = cpu_to_le16(sizeof(u8));
  213. oper_ntf->oper_mode = ieee_oper_ntf->oper_mode;
  214. *buffer += sizeof(*oper_ntf);
  215. ret_len += sizeof(*oper_ntf);
  216. }
  217. return ret_len;
  218. }
  219. int mwifiex_cmd_11ac_cfg(struct mwifiex_private *priv,
  220. struct host_cmd_ds_command *cmd, u16 cmd_action,
  221. struct mwifiex_11ac_vht_cfg *cfg)
  222. {
  223. struct host_cmd_11ac_vht_cfg *vhtcfg = &cmd->params.vht_cfg;
  224. cmd->command = cpu_to_le16(HostCmd_CMD_11AC_CFG);
  225. cmd->size = cpu_to_le16(sizeof(struct host_cmd_11ac_vht_cfg) +
  226. S_DS_GEN);
  227. vhtcfg->action = cpu_to_le16(cmd_action);
  228. vhtcfg->band_config = cfg->band_config;
  229. vhtcfg->misc_config = cfg->misc_config;
  230. vhtcfg->cap_info = cpu_to_le32(cfg->cap_info);
  231. vhtcfg->mcs_tx_set = cpu_to_le32(cfg->mcs_tx_set);
  232. vhtcfg->mcs_rx_set = cpu_to_le32(cfg->mcs_rx_set);
  233. return 0;
  234. }
  235. /* This function initializes the BlockACK setup information for given
  236. * mwifiex_private structure for 11ac enabled networks.
  237. */
  238. void mwifiex_set_11ac_ba_params(struct mwifiex_private *priv)
  239. {
  240. priv->add_ba_param.timeout = MWIFIEX_DEFAULT_BLOCK_ACK_TIMEOUT;
  241. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
  242. priv->add_ba_param.tx_win_size =
  243. MWIFIEX_11AC_UAP_AMPDU_DEF_TXWINSIZE;
  244. priv->add_ba_param.rx_win_size =
  245. MWIFIEX_11AC_UAP_AMPDU_DEF_RXWINSIZE;
  246. } else {
  247. priv->add_ba_param.tx_win_size =
  248. MWIFIEX_11AC_STA_AMPDU_DEF_TXWINSIZE;
  249. priv->add_ba_param.rx_win_size =
  250. MWIFIEX_11AC_STA_AMPDU_DEF_RXWINSIZE;
  251. }
  252. return;
  253. }
  254. bool mwifiex_is_bss_in_11ac_mode(struct mwifiex_private *priv)
  255. {
  256. struct mwifiex_bssdescriptor *bss_desc;
  257. struct ieee80211_vht_operation *vht_oper;
  258. bss_desc = &priv->curr_bss_params.bss_descriptor;
  259. vht_oper = bss_desc->bcn_vht_oper;
  260. if (!bss_desc->bcn_vht_cap || !vht_oper)
  261. return false;
  262. if (vht_oper->chan_width == IEEE80211_VHT_CHANWIDTH_USE_HT)
  263. return false;
  264. return true;
  265. }
  266. u8 mwifiex_get_center_freq_index(struct mwifiex_private *priv, u8 band,
  267. u32 pri_chan, u8 chan_bw)
  268. {
  269. u8 center_freq_idx = 0;
  270. if (band & BAND_AAC) {
  271. switch (pri_chan) {
  272. case 36:
  273. case 40:
  274. case 44:
  275. case 48:
  276. if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
  277. center_freq_idx = 42;
  278. break;
  279. case 52:
  280. case 56:
  281. case 60:
  282. case 64:
  283. if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
  284. center_freq_idx = 58;
  285. else if (chan_bw == IEEE80211_VHT_CHANWIDTH_160MHZ)
  286. center_freq_idx = 50;
  287. break;
  288. case 100:
  289. case 104:
  290. case 108:
  291. case 112:
  292. if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
  293. center_freq_idx = 106;
  294. break;
  295. case 116:
  296. case 120:
  297. case 124:
  298. case 128:
  299. if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
  300. center_freq_idx = 122;
  301. else if (chan_bw == IEEE80211_VHT_CHANWIDTH_160MHZ)
  302. center_freq_idx = 114;
  303. break;
  304. case 132:
  305. case 136:
  306. case 140:
  307. case 144:
  308. if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
  309. center_freq_idx = 138;
  310. break;
  311. case 149:
  312. case 153:
  313. case 157:
  314. case 161:
  315. if (chan_bw == IEEE80211_VHT_CHANWIDTH_80MHZ)
  316. center_freq_idx = 155;
  317. break;
  318. default:
  319. center_freq_idx = 42;
  320. }
  321. }
  322. return center_freq_idx;
  323. }