vht.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /*
  2. * VHT handling
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/ieee80211.h>
  9. #include <linux/export.h>
  10. #include <net/mac80211.h>
  11. #include "ieee80211_i.h"
  12. #include "rate.h"
  13. static void __check_vhtcap_disable(struct ieee80211_sub_if_data *sdata,
  14. struct ieee80211_sta_vht_cap *vht_cap,
  15. u32 flag)
  16. {
  17. __le32 le_flag = cpu_to_le32(flag);
  18. if (sdata->u.mgd.vht_capa_mask.vht_cap_info & le_flag &&
  19. !(sdata->u.mgd.vht_capa.vht_cap_info & le_flag))
  20. vht_cap->cap &= ~flag;
  21. }
  22. void ieee80211_apply_vhtcap_overrides(struct ieee80211_sub_if_data *sdata,
  23. struct ieee80211_sta_vht_cap *vht_cap)
  24. {
  25. int i;
  26. u16 rxmcs_mask, rxmcs_cap, rxmcs_n, txmcs_mask, txmcs_cap, txmcs_n;
  27. if (!vht_cap->vht_supported)
  28. return;
  29. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  30. return;
  31. __check_vhtcap_disable(sdata, vht_cap,
  32. IEEE80211_VHT_CAP_RXLDPC);
  33. __check_vhtcap_disable(sdata, vht_cap,
  34. IEEE80211_VHT_CAP_SHORT_GI_80);
  35. __check_vhtcap_disable(sdata, vht_cap,
  36. IEEE80211_VHT_CAP_SHORT_GI_160);
  37. __check_vhtcap_disable(sdata, vht_cap,
  38. IEEE80211_VHT_CAP_TXSTBC);
  39. __check_vhtcap_disable(sdata, vht_cap,
  40. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE);
  41. __check_vhtcap_disable(sdata, vht_cap,
  42. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE);
  43. __check_vhtcap_disable(sdata, vht_cap,
  44. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN);
  45. __check_vhtcap_disable(sdata, vht_cap,
  46. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN);
  47. /* Allow user to decrease AMPDU length exponent */
  48. if (sdata->u.mgd.vht_capa_mask.vht_cap_info &
  49. cpu_to_le32(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK)) {
  50. u32 cap, n;
  51. n = le32_to_cpu(sdata->u.mgd.vht_capa.vht_cap_info) &
  52. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
  53. n >>= IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  54. cap = vht_cap->cap & IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
  55. cap >>= IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  56. if (n < cap) {
  57. vht_cap->cap &=
  58. ~IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
  59. vht_cap->cap |=
  60. n << IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  61. }
  62. }
  63. /* Allow the user to decrease MCSes */
  64. rxmcs_mask =
  65. le16_to_cpu(sdata->u.mgd.vht_capa_mask.supp_mcs.rx_mcs_map);
  66. rxmcs_n = le16_to_cpu(sdata->u.mgd.vht_capa.supp_mcs.rx_mcs_map);
  67. rxmcs_n &= rxmcs_mask;
  68. rxmcs_cap = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
  69. txmcs_mask =
  70. le16_to_cpu(sdata->u.mgd.vht_capa_mask.supp_mcs.tx_mcs_map);
  71. txmcs_n = le16_to_cpu(sdata->u.mgd.vht_capa.supp_mcs.tx_mcs_map);
  72. txmcs_n &= txmcs_mask;
  73. txmcs_cap = le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
  74. for (i = 0; i < 8; i++) {
  75. u8 m, n, c;
  76. m = (rxmcs_mask >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  77. n = (rxmcs_n >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  78. c = (rxmcs_cap >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  79. if (m && ((c != IEEE80211_VHT_MCS_NOT_SUPPORTED && n < c) ||
  80. n == IEEE80211_VHT_MCS_NOT_SUPPORTED)) {
  81. rxmcs_cap &= ~(3 << 2*i);
  82. rxmcs_cap |= (rxmcs_n & (3 << 2*i));
  83. }
  84. m = (txmcs_mask >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  85. n = (txmcs_n >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  86. c = (txmcs_cap >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  87. if (m && ((c != IEEE80211_VHT_MCS_NOT_SUPPORTED && n < c) ||
  88. n == IEEE80211_VHT_MCS_NOT_SUPPORTED)) {
  89. txmcs_cap &= ~(3 << 2*i);
  90. txmcs_cap |= (txmcs_n & (3 << 2*i));
  91. }
  92. }
  93. vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_cap);
  94. vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_cap);
  95. }
  96. void
  97. ieee80211_vht_cap_ie_to_sta_vht_cap(struct ieee80211_sub_if_data *sdata,
  98. struct ieee80211_supported_band *sband,
  99. const struct ieee80211_vht_cap *vht_cap_ie,
  100. struct sta_info *sta)
  101. {
  102. struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
  103. struct ieee80211_sta_vht_cap own_cap;
  104. u32 cap_info, i;
  105. memset(vht_cap, 0, sizeof(*vht_cap));
  106. if (!sta->sta.ht_cap.ht_supported)
  107. return;
  108. if (!vht_cap_ie || !sband->vht_cap.vht_supported)
  109. return;
  110. /*
  111. * A VHT STA must support 40 MHz, but if we verify that here
  112. * then we break a few things - some APs (e.g. Netgear R6300v2
  113. * and others based on the BCM4360 chipset) will unset this
  114. * capability bit when operating in 20 MHz.
  115. */
  116. vht_cap->vht_supported = true;
  117. own_cap = sband->vht_cap;
  118. /*
  119. * If user has specified capability overrides, take care
  120. * of that if the station we're setting up is the AP that
  121. * we advertised a restricted capability set to. Override
  122. * our own capabilities and then use those below.
  123. */
  124. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  125. !test_sta_flag(sta, WLAN_STA_TDLS_PEER))
  126. ieee80211_apply_vhtcap_overrides(sdata, &own_cap);
  127. /* take some capabilities as-is */
  128. cap_info = le32_to_cpu(vht_cap_ie->vht_cap_info);
  129. vht_cap->cap = cap_info;
  130. vht_cap->cap &= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 |
  131. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 |
  132. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
  133. IEEE80211_VHT_CAP_RXLDPC |
  134. IEEE80211_VHT_CAP_VHT_TXOP_PS |
  135. IEEE80211_VHT_CAP_HTC_VHT |
  136. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
  137. IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB |
  138. IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB |
  139. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
  140. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN;
  141. /* and some based on our own capabilities */
  142. switch (own_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
  143. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
  144. vht_cap->cap |= cap_info &
  145. IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  146. break;
  147. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
  148. vht_cap->cap |= cap_info &
  149. IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  150. break;
  151. default:
  152. /* nothing */
  153. break;
  154. }
  155. /* symmetric capabilities */
  156. vht_cap->cap |= cap_info & own_cap.cap &
  157. (IEEE80211_VHT_CAP_SHORT_GI_80 |
  158. IEEE80211_VHT_CAP_SHORT_GI_160);
  159. /* remaining ones */
  160. if (own_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
  161. vht_cap->cap |= cap_info &
  162. (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  163. IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK);
  164. if (own_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
  165. vht_cap->cap |= cap_info &
  166. (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  167. IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK);
  168. if (own_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
  169. vht_cap->cap |= cap_info &
  170. IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  171. if (own_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
  172. vht_cap->cap |= cap_info &
  173. IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
  174. if (own_cap.cap & IEEE80211_VHT_CAP_TXSTBC)
  175. vht_cap->cap |= cap_info & IEEE80211_VHT_CAP_RXSTBC_MASK;
  176. if (own_cap.cap & IEEE80211_VHT_CAP_RXSTBC_MASK)
  177. vht_cap->cap |= cap_info & IEEE80211_VHT_CAP_TXSTBC;
  178. /* Copy peer MCS info, the driver might need them. */
  179. memcpy(&vht_cap->vht_mcs, &vht_cap_ie->supp_mcs,
  180. sizeof(struct ieee80211_vht_mcs_info));
  181. /* but also restrict MCSes */
  182. for (i = 0; i < 8; i++) {
  183. u16 own_rx, own_tx, peer_rx, peer_tx;
  184. own_rx = le16_to_cpu(own_cap.vht_mcs.rx_mcs_map);
  185. own_rx = (own_rx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  186. own_tx = le16_to_cpu(own_cap.vht_mcs.tx_mcs_map);
  187. own_tx = (own_tx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  188. peer_rx = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
  189. peer_rx = (peer_rx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  190. peer_tx = le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
  191. peer_tx = (peer_tx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  192. if (peer_tx != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  193. if (own_rx == IEEE80211_VHT_MCS_NOT_SUPPORTED)
  194. peer_tx = IEEE80211_VHT_MCS_NOT_SUPPORTED;
  195. else if (own_rx < peer_tx)
  196. peer_tx = own_rx;
  197. }
  198. if (peer_rx != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  199. if (own_tx == IEEE80211_VHT_MCS_NOT_SUPPORTED)
  200. peer_rx = IEEE80211_VHT_MCS_NOT_SUPPORTED;
  201. else if (own_tx < peer_rx)
  202. peer_rx = own_tx;
  203. }
  204. vht_cap->vht_mcs.rx_mcs_map &=
  205. ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << i * 2);
  206. vht_cap->vht_mcs.rx_mcs_map |= cpu_to_le16(peer_rx << i * 2);
  207. vht_cap->vht_mcs.tx_mcs_map &=
  208. ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << i * 2);
  209. vht_cap->vht_mcs.tx_mcs_map |= cpu_to_le16(peer_tx << i * 2);
  210. }
  211. /* finally set up the bandwidth */
  212. switch (vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
  213. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
  214. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
  215. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
  216. break;
  217. default:
  218. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80;
  219. }
  220. sta->sta.bandwidth = ieee80211_sta_cur_vht_bw(sta);
  221. }
  222. enum ieee80211_sta_rx_bandwidth ieee80211_sta_cap_rx_bw(struct sta_info *sta)
  223. {
  224. struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
  225. u32 cap_width;
  226. if (!vht_cap->vht_supported)
  227. return sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  228. IEEE80211_STA_RX_BW_40 :
  229. IEEE80211_STA_RX_BW_20;
  230. cap_width = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  231. if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
  232. cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
  233. return IEEE80211_STA_RX_BW_160;
  234. return IEEE80211_STA_RX_BW_80;
  235. }
  236. static enum ieee80211_sta_rx_bandwidth
  237. ieee80211_chan_width_to_rx_bw(enum nl80211_chan_width width)
  238. {
  239. switch (width) {
  240. case NL80211_CHAN_WIDTH_20_NOHT:
  241. case NL80211_CHAN_WIDTH_20:
  242. return IEEE80211_STA_RX_BW_20;
  243. case NL80211_CHAN_WIDTH_40:
  244. return IEEE80211_STA_RX_BW_40;
  245. case NL80211_CHAN_WIDTH_80:
  246. return IEEE80211_STA_RX_BW_80;
  247. case NL80211_CHAN_WIDTH_160:
  248. case NL80211_CHAN_WIDTH_80P80:
  249. return IEEE80211_STA_RX_BW_160;
  250. default:
  251. WARN_ON_ONCE(1);
  252. return IEEE80211_STA_RX_BW_20;
  253. }
  254. }
  255. enum ieee80211_sta_rx_bandwidth ieee80211_sta_cur_vht_bw(struct sta_info *sta)
  256. {
  257. struct ieee80211_sub_if_data *sdata = sta->sdata;
  258. enum ieee80211_sta_rx_bandwidth bw;
  259. bw = ieee80211_chan_width_to_rx_bw(sdata->vif.bss_conf.chandef.width);
  260. bw = min(bw, ieee80211_sta_cap_rx_bw(sta));
  261. bw = min(bw, sta->cur_max_bandwidth);
  262. return bw;
  263. }
  264. void ieee80211_sta_set_rx_nss(struct sta_info *sta)
  265. {
  266. u8 ht_rx_nss = 0, vht_rx_nss = 0;
  267. /* if we received a notification already don't overwrite it */
  268. if (sta->sta.rx_nss)
  269. return;
  270. if (sta->sta.ht_cap.ht_supported) {
  271. if (sta->sta.ht_cap.mcs.rx_mask[0])
  272. ht_rx_nss++;
  273. if (sta->sta.ht_cap.mcs.rx_mask[1])
  274. ht_rx_nss++;
  275. if (sta->sta.ht_cap.mcs.rx_mask[2])
  276. ht_rx_nss++;
  277. if (sta->sta.ht_cap.mcs.rx_mask[3])
  278. ht_rx_nss++;
  279. /* FIXME: consider rx_highest? */
  280. }
  281. if (sta->sta.vht_cap.vht_supported) {
  282. int i;
  283. u16 rx_mcs_map;
  284. rx_mcs_map = le16_to_cpu(sta->sta.vht_cap.vht_mcs.rx_mcs_map);
  285. for (i = 7; i >= 0; i--) {
  286. u8 mcs = (rx_mcs_map >> (2 * i)) & 3;
  287. if (mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  288. vht_rx_nss = i + 1;
  289. break;
  290. }
  291. }
  292. /* FIXME: consider rx_highest? */
  293. }
  294. ht_rx_nss = max(ht_rx_nss, vht_rx_nss);
  295. sta->sta.rx_nss = max_t(u8, 1, ht_rx_nss);
  296. }
  297. u32 __ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
  298. struct sta_info *sta, u8 opmode,
  299. enum ieee80211_band band, bool nss_only)
  300. {
  301. struct ieee80211_local *local = sdata->local;
  302. struct ieee80211_supported_band *sband;
  303. enum ieee80211_sta_rx_bandwidth new_bw;
  304. u32 changed = 0;
  305. u8 nss;
  306. sband = local->hw.wiphy->bands[band];
  307. /* ignore - no support for BF yet */
  308. if (opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)
  309. return 0;
  310. nss = opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
  311. nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
  312. nss += 1;
  313. if (sta->sta.rx_nss != nss) {
  314. sta->sta.rx_nss = nss;
  315. changed |= IEEE80211_RC_NSS_CHANGED;
  316. }
  317. if (nss_only)
  318. return changed;
  319. switch (opmode & IEEE80211_OPMODE_NOTIF_CHANWIDTH_MASK) {
  320. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_20MHZ:
  321. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_20;
  322. break;
  323. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_40MHZ:
  324. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_40;
  325. break;
  326. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_80MHZ:
  327. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80;
  328. break;
  329. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_160MHZ:
  330. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
  331. break;
  332. }
  333. new_bw = ieee80211_sta_cur_vht_bw(sta);
  334. if (new_bw != sta->sta.bandwidth) {
  335. sta->sta.bandwidth = new_bw;
  336. changed |= IEEE80211_RC_BW_CHANGED;
  337. }
  338. return changed;
  339. }
  340. void ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
  341. struct sta_info *sta, u8 opmode,
  342. enum ieee80211_band band, bool nss_only)
  343. {
  344. struct ieee80211_local *local = sdata->local;
  345. struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
  346. u32 changed = __ieee80211_vht_handle_opmode(sdata, sta, opmode,
  347. band, nss_only);
  348. if (changed > 0)
  349. rate_control_rate_update(local, sband, sta, changed);
  350. }