vht.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * VHT handling
  4. *
  5. * Portions of this file
  6. * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
  7. * Copyright (C) 2018 - 2023 Intel Corporation
  8. */
  9. #include <linux/ieee80211.h>
  10. #include <linux/export.h>
  11. #include <net/mac80211.h>
  12. #include "ieee80211_i.h"
  13. #include "rate.h"
  14. static void __check_vhtcap_disable(struct ieee80211_sub_if_data *sdata,
  15. struct ieee80211_sta_vht_cap *vht_cap,
  16. u32 flag)
  17. {
  18. __le32 le_flag = cpu_to_le32(flag);
  19. if (sdata->u.mgd.vht_capa_mask.vht_cap_info & le_flag &&
  20. !(sdata->u.mgd.vht_capa.vht_cap_info & le_flag))
  21. vht_cap->cap &= ~flag;
  22. }
  23. void ieee80211_apply_vhtcap_overrides(struct ieee80211_sub_if_data *sdata,
  24. struct ieee80211_sta_vht_cap *vht_cap)
  25. {
  26. int i;
  27. u16 rxmcs_mask, rxmcs_cap, rxmcs_n, txmcs_mask, txmcs_cap, txmcs_n;
  28. if (!vht_cap->vht_supported)
  29. return;
  30. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  31. return;
  32. __check_vhtcap_disable(sdata, vht_cap,
  33. IEEE80211_VHT_CAP_RXLDPC);
  34. __check_vhtcap_disable(sdata, vht_cap,
  35. IEEE80211_VHT_CAP_SHORT_GI_80);
  36. __check_vhtcap_disable(sdata, vht_cap,
  37. IEEE80211_VHT_CAP_SHORT_GI_160);
  38. __check_vhtcap_disable(sdata, vht_cap,
  39. IEEE80211_VHT_CAP_TXSTBC);
  40. __check_vhtcap_disable(sdata, vht_cap,
  41. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE);
  42. __check_vhtcap_disable(sdata, vht_cap,
  43. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE);
  44. __check_vhtcap_disable(sdata, vht_cap,
  45. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN);
  46. __check_vhtcap_disable(sdata, vht_cap,
  47. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN);
  48. /* Allow user to decrease AMPDU length exponent */
  49. if (sdata->u.mgd.vht_capa_mask.vht_cap_info &
  50. cpu_to_le32(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK)) {
  51. u32 cap, n;
  52. n = le32_to_cpu(sdata->u.mgd.vht_capa.vht_cap_info) &
  53. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
  54. n >>= IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  55. cap = vht_cap->cap & IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
  56. cap >>= IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  57. if (n < cap) {
  58. vht_cap->cap &=
  59. ~IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
  60. vht_cap->cap |=
  61. n << IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  62. }
  63. }
  64. /* Allow the user to decrease MCSes */
  65. rxmcs_mask =
  66. le16_to_cpu(sdata->u.mgd.vht_capa_mask.supp_mcs.rx_mcs_map);
  67. rxmcs_n = le16_to_cpu(sdata->u.mgd.vht_capa.supp_mcs.rx_mcs_map);
  68. rxmcs_n &= rxmcs_mask;
  69. rxmcs_cap = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
  70. txmcs_mask =
  71. le16_to_cpu(sdata->u.mgd.vht_capa_mask.supp_mcs.tx_mcs_map);
  72. txmcs_n = le16_to_cpu(sdata->u.mgd.vht_capa.supp_mcs.tx_mcs_map);
  73. txmcs_n &= txmcs_mask;
  74. txmcs_cap = le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
  75. for (i = 0; i < 8; i++) {
  76. u8 m, n, c;
  77. m = (rxmcs_mask >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  78. n = (rxmcs_n >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  79. c = (rxmcs_cap >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  80. if (m && ((c != IEEE80211_VHT_MCS_NOT_SUPPORTED && n < c) ||
  81. n == IEEE80211_VHT_MCS_NOT_SUPPORTED)) {
  82. rxmcs_cap &= ~(3 << 2*i);
  83. rxmcs_cap |= (rxmcs_n & (3 << 2*i));
  84. }
  85. m = (txmcs_mask >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  86. n = (txmcs_n >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  87. c = (txmcs_cap >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  88. if (m && ((c != IEEE80211_VHT_MCS_NOT_SUPPORTED && n < c) ||
  89. n == IEEE80211_VHT_MCS_NOT_SUPPORTED)) {
  90. txmcs_cap &= ~(3 << 2*i);
  91. txmcs_cap |= (txmcs_n & (3 << 2*i));
  92. }
  93. }
  94. vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_cap);
  95. vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_cap);
  96. }
  97. void
  98. ieee80211_vht_cap_ie_to_sta_vht_cap(struct ieee80211_sub_if_data *sdata,
  99. struct ieee80211_supported_band *sband,
  100. const struct ieee80211_vht_cap *vht_cap_ie,
  101. const struct ieee80211_vht_cap *vht_cap_ie2,
  102. struct link_sta_info *link_sta)
  103. {
  104. struct ieee80211_sta_vht_cap *vht_cap = &link_sta->pub->vht_cap;
  105. struct ieee80211_sta_vht_cap own_cap;
  106. u32 cap_info, i;
  107. bool have_80mhz;
  108. u32 mpdu_len;
  109. memset(vht_cap, 0, sizeof(*vht_cap));
  110. if (!link_sta->pub->ht_cap.ht_supported)
  111. return;
  112. if (!vht_cap_ie || !sband->vht_cap.vht_supported)
  113. return;
  114. /* Allow VHT if at least one channel on the sband supports 80 MHz */
  115. have_80mhz = false;
  116. for (i = 0; i < sband->n_channels; i++) {
  117. if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
  118. IEEE80211_CHAN_NO_80MHZ))
  119. continue;
  120. have_80mhz = true;
  121. break;
  122. }
  123. if (!have_80mhz)
  124. return;
  125. /*
  126. * A VHT STA must support 40 MHz, but if we verify that here
  127. * then we break a few things - some APs (e.g. Netgear R6300v2
  128. * and others based on the BCM4360 chipset) will unset this
  129. * capability bit when operating in 20 MHz.
  130. */
  131. vht_cap->vht_supported = true;
  132. own_cap = sband->vht_cap;
  133. /*
  134. * If user has specified capability overrides, take care
  135. * of that if the station we're setting up is the AP that
  136. * we advertised a restricted capability set to. Override
  137. * our own capabilities and then use those below.
  138. */
  139. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  140. !test_sta_flag(link_sta->sta, WLAN_STA_TDLS_PEER))
  141. ieee80211_apply_vhtcap_overrides(sdata, &own_cap);
  142. /* take some capabilities as-is */
  143. cap_info = le32_to_cpu(vht_cap_ie->vht_cap_info);
  144. vht_cap->cap = cap_info;
  145. vht_cap->cap &= IEEE80211_VHT_CAP_RXLDPC |
  146. IEEE80211_VHT_CAP_VHT_TXOP_PS |
  147. IEEE80211_VHT_CAP_HTC_VHT |
  148. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
  149. IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB |
  150. IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB |
  151. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
  152. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN;
  153. vht_cap->cap |= min_t(u32, cap_info & IEEE80211_VHT_CAP_MAX_MPDU_MASK,
  154. own_cap.cap & IEEE80211_VHT_CAP_MAX_MPDU_MASK);
  155. /* and some based on our own capabilities */
  156. switch (own_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
  157. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
  158. vht_cap->cap |= cap_info &
  159. IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  160. break;
  161. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
  162. vht_cap->cap |= cap_info &
  163. IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  164. break;
  165. default:
  166. /* nothing */
  167. break;
  168. }
  169. /* symmetric capabilities */
  170. vht_cap->cap |= cap_info & own_cap.cap &
  171. (IEEE80211_VHT_CAP_SHORT_GI_80 |
  172. IEEE80211_VHT_CAP_SHORT_GI_160);
  173. /* remaining ones */
  174. if (own_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
  175. vht_cap->cap |= cap_info &
  176. (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  177. IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK);
  178. if (own_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
  179. vht_cap->cap |= cap_info &
  180. (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  181. IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK);
  182. if (own_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
  183. vht_cap->cap |= cap_info &
  184. IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  185. if (own_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
  186. vht_cap->cap |= cap_info &
  187. IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
  188. if (own_cap.cap & IEEE80211_VHT_CAP_TXSTBC)
  189. vht_cap->cap |= cap_info & IEEE80211_VHT_CAP_RXSTBC_MASK;
  190. if (own_cap.cap & IEEE80211_VHT_CAP_RXSTBC_MASK)
  191. vht_cap->cap |= cap_info & IEEE80211_VHT_CAP_TXSTBC;
  192. /* Copy peer MCS info, the driver might need them. */
  193. memcpy(&vht_cap->vht_mcs, &vht_cap_ie->supp_mcs,
  194. sizeof(struct ieee80211_vht_mcs_info));
  195. /* copy EXT_NSS_BW Support value or remove the capability */
  196. if (ieee80211_hw_check(&sdata->local->hw, SUPPORTS_VHT_EXT_NSS_BW))
  197. vht_cap->cap |= (cap_info & IEEE80211_VHT_CAP_EXT_NSS_BW_MASK);
  198. else
  199. vht_cap->vht_mcs.tx_highest &=
  200. ~cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE);
  201. /* but also restrict MCSes */
  202. for (i = 0; i < 8; i++) {
  203. u16 own_rx, own_tx, peer_rx, peer_tx;
  204. own_rx = le16_to_cpu(own_cap.vht_mcs.rx_mcs_map);
  205. own_rx = (own_rx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  206. own_tx = le16_to_cpu(own_cap.vht_mcs.tx_mcs_map);
  207. own_tx = (own_tx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  208. peer_rx = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
  209. peer_rx = (peer_rx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  210. peer_tx = le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
  211. peer_tx = (peer_tx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  212. if (peer_tx != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  213. if (own_rx == IEEE80211_VHT_MCS_NOT_SUPPORTED)
  214. peer_tx = IEEE80211_VHT_MCS_NOT_SUPPORTED;
  215. else if (own_rx < peer_tx)
  216. peer_tx = own_rx;
  217. }
  218. if (peer_rx != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  219. if (own_tx == IEEE80211_VHT_MCS_NOT_SUPPORTED)
  220. peer_rx = IEEE80211_VHT_MCS_NOT_SUPPORTED;
  221. else if (own_tx < peer_rx)
  222. peer_rx = own_tx;
  223. }
  224. vht_cap->vht_mcs.rx_mcs_map &=
  225. ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << i * 2);
  226. vht_cap->vht_mcs.rx_mcs_map |= cpu_to_le16(peer_rx << i * 2);
  227. vht_cap->vht_mcs.tx_mcs_map &=
  228. ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << i * 2);
  229. vht_cap->vht_mcs.tx_mcs_map |= cpu_to_le16(peer_tx << i * 2);
  230. }
  231. /*
  232. * This is a workaround for VHT-enabled STAs which break the spec
  233. * and have the VHT-MCS Rx map filled in with value 3 for all eight
  234. * spacial streams, an example is AR9462.
  235. *
  236. * As per spec, in section 22.1.1 Introduction to the VHT PHY
  237. * A VHT STA shall support at least single spactial stream VHT-MCSs
  238. * 0 to 7 (transmit and receive) in all supported channel widths.
  239. */
  240. if (vht_cap->vht_mcs.rx_mcs_map == cpu_to_le16(0xFFFF)) {
  241. vht_cap->vht_supported = false;
  242. sdata_info(sdata,
  243. "Ignoring VHT IE from %pM (link:%pM) due to invalid rx_mcs_map\n",
  244. link_sta->sta->addr, link_sta->addr);
  245. return;
  246. }
  247. /* finally set up the bandwidth */
  248. switch (vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
  249. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
  250. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
  251. link_sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
  252. break;
  253. default:
  254. link_sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80;
  255. if (!(vht_cap->vht_mcs.tx_highest &
  256. cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE)))
  257. break;
  258. /*
  259. * If this is non-zero, then it does support 160 MHz after all,
  260. * in one form or the other. We don't distinguish here (or even
  261. * above) between 160 and 80+80 yet.
  262. */
  263. if (cap_info & IEEE80211_VHT_CAP_EXT_NSS_BW_MASK)
  264. link_sta->cur_max_bandwidth =
  265. IEEE80211_STA_RX_BW_160;
  266. }
  267. link_sta->pub->bandwidth = ieee80211_sta_cur_vht_bw(link_sta);
  268. /*
  269. * Work around the Cisco 9115 FW 17.3 bug by taking the min of
  270. * both reported MPDU lengths.
  271. */
  272. mpdu_len = vht_cap->cap & IEEE80211_VHT_CAP_MAX_MPDU_MASK;
  273. if (vht_cap_ie2)
  274. mpdu_len = min_t(u32, mpdu_len,
  275. le32_get_bits(vht_cap_ie2->vht_cap_info,
  276. IEEE80211_VHT_CAP_MAX_MPDU_MASK));
  277. /*
  278. * FIXME - should the amsdu len be per link? store per link
  279. * and maintain a minimum?
  280. */
  281. switch (mpdu_len) {
  282. case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454:
  283. link_sta->pub->agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_11454;
  284. break;
  285. case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991:
  286. link_sta->pub->agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_7991;
  287. break;
  288. case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895:
  289. default:
  290. link_sta->pub->agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_3895;
  291. break;
  292. }
  293. ieee80211_sta_recalc_aggregates(&link_sta->sta->sta);
  294. }
  295. /* FIXME: move this to some better location - parses HE/EHT now */
  296. enum ieee80211_sta_rx_bandwidth
  297. ieee80211_sta_cap_rx_bw(struct link_sta_info *link_sta)
  298. {
  299. unsigned int link_id = link_sta->link_id;
  300. struct ieee80211_sub_if_data *sdata = link_sta->sta->sdata;
  301. struct ieee80211_sta_vht_cap *vht_cap = &link_sta->pub->vht_cap;
  302. struct ieee80211_sta_he_cap *he_cap = &link_sta->pub->he_cap;
  303. struct ieee80211_sta_eht_cap *eht_cap = &link_sta->pub->eht_cap;
  304. u32 cap_width;
  305. if (he_cap->has_he) {
  306. struct ieee80211_bss_conf *link_conf;
  307. enum ieee80211_sta_rx_bandwidth ret;
  308. u8 info;
  309. rcu_read_lock();
  310. link_conf = rcu_dereference(sdata->vif.link_conf[link_id]);
  311. if (eht_cap->has_eht &&
  312. link_conf->chandef.chan->band == NL80211_BAND_6GHZ) {
  313. info = eht_cap->eht_cap_elem.phy_cap_info[0];
  314. if (info & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ) {
  315. ret = IEEE80211_STA_RX_BW_320;
  316. goto out;
  317. }
  318. }
  319. info = he_cap->he_cap_elem.phy_cap_info[0];
  320. if (link_conf->chandef.chan->band == NL80211_BAND_2GHZ) {
  321. if (info & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G)
  322. ret = IEEE80211_STA_RX_BW_40;
  323. else
  324. ret = IEEE80211_STA_RX_BW_20;
  325. goto out;
  326. }
  327. if (info & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G ||
  328. info & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)
  329. ret = IEEE80211_STA_RX_BW_160;
  330. else if (info & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G)
  331. ret = IEEE80211_STA_RX_BW_80;
  332. else
  333. ret = IEEE80211_STA_RX_BW_20;
  334. out:
  335. rcu_read_unlock();
  336. return ret;
  337. }
  338. if (!vht_cap->vht_supported)
  339. return link_sta->pub->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  340. IEEE80211_STA_RX_BW_40 :
  341. IEEE80211_STA_RX_BW_20;
  342. cap_width = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  343. if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
  344. cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
  345. return IEEE80211_STA_RX_BW_160;
  346. /*
  347. * If this is non-zero, then it does support 160 MHz after all,
  348. * in one form or the other. We don't distinguish here (or even
  349. * above) between 160 and 80+80 yet.
  350. */
  351. if (vht_cap->cap & IEEE80211_VHT_CAP_EXT_NSS_BW_MASK)
  352. return IEEE80211_STA_RX_BW_160;
  353. return IEEE80211_STA_RX_BW_80;
  354. }
  355. enum nl80211_chan_width
  356. ieee80211_sta_cap_chan_bw(struct link_sta_info *link_sta)
  357. {
  358. struct ieee80211_sta_vht_cap *vht_cap = &link_sta->pub->vht_cap;
  359. u32 cap_width;
  360. if (!vht_cap->vht_supported) {
  361. if (!link_sta->pub->ht_cap.ht_supported)
  362. return NL80211_CHAN_WIDTH_20_NOHT;
  363. return link_sta->pub->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  364. NL80211_CHAN_WIDTH_40 : NL80211_CHAN_WIDTH_20;
  365. }
  366. cap_width = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  367. if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ)
  368. return NL80211_CHAN_WIDTH_160;
  369. else if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
  370. return NL80211_CHAN_WIDTH_80P80;
  371. return NL80211_CHAN_WIDTH_80;
  372. }
  373. enum nl80211_chan_width
  374. ieee80211_sta_rx_bw_to_chan_width(struct link_sta_info *link_sta)
  375. {
  376. enum ieee80211_sta_rx_bandwidth cur_bw =
  377. link_sta->pub->bandwidth;
  378. struct ieee80211_sta_vht_cap *vht_cap =
  379. &link_sta->pub->vht_cap;
  380. u32 cap_width;
  381. switch (cur_bw) {
  382. case IEEE80211_STA_RX_BW_20:
  383. if (!link_sta->pub->ht_cap.ht_supported)
  384. return NL80211_CHAN_WIDTH_20_NOHT;
  385. else
  386. return NL80211_CHAN_WIDTH_20;
  387. case IEEE80211_STA_RX_BW_40:
  388. return NL80211_CHAN_WIDTH_40;
  389. case IEEE80211_STA_RX_BW_80:
  390. return NL80211_CHAN_WIDTH_80;
  391. case IEEE80211_STA_RX_BW_160:
  392. cap_width =
  393. vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  394. if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ)
  395. return NL80211_CHAN_WIDTH_160;
  396. return NL80211_CHAN_WIDTH_80P80;
  397. default:
  398. return NL80211_CHAN_WIDTH_20;
  399. }
  400. }
  401. enum ieee80211_sta_rx_bandwidth
  402. ieee80211_chan_width_to_rx_bw(enum nl80211_chan_width width)
  403. {
  404. switch (width) {
  405. case NL80211_CHAN_WIDTH_20_NOHT:
  406. case NL80211_CHAN_WIDTH_20:
  407. return IEEE80211_STA_RX_BW_20;
  408. case NL80211_CHAN_WIDTH_40:
  409. return IEEE80211_STA_RX_BW_40;
  410. case NL80211_CHAN_WIDTH_80:
  411. return IEEE80211_STA_RX_BW_80;
  412. case NL80211_CHAN_WIDTH_160:
  413. case NL80211_CHAN_WIDTH_80P80:
  414. return IEEE80211_STA_RX_BW_160;
  415. case NL80211_CHAN_WIDTH_320:
  416. return IEEE80211_STA_RX_BW_320;
  417. default:
  418. WARN_ON_ONCE(1);
  419. return IEEE80211_STA_RX_BW_20;
  420. }
  421. }
  422. /* FIXME: rename/move - this deals with everything not just VHT */
  423. enum ieee80211_sta_rx_bandwidth
  424. ieee80211_sta_cur_vht_bw(struct link_sta_info *link_sta)
  425. {
  426. struct sta_info *sta = link_sta->sta;
  427. struct ieee80211_bss_conf *link_conf;
  428. enum nl80211_chan_width bss_width;
  429. enum ieee80211_sta_rx_bandwidth bw;
  430. rcu_read_lock();
  431. link_conf = rcu_dereference(sta->sdata->vif.link_conf[link_sta->link_id]);
  432. if (WARN_ON(!link_conf))
  433. bss_width = NL80211_CHAN_WIDTH_20_NOHT;
  434. else
  435. bss_width = link_conf->chandef.width;
  436. rcu_read_unlock();
  437. bw = ieee80211_sta_cap_rx_bw(link_sta);
  438. bw = min(bw, link_sta->cur_max_bandwidth);
  439. /* Don't consider AP's bandwidth for TDLS peers, section 11.23.1 of
  440. * IEEE80211-2016 specification makes higher bandwidth operation
  441. * possible on the TDLS link if the peers have wider bandwidth
  442. * capability.
  443. *
  444. * However, in this case, and only if the TDLS peer is authorized,
  445. * limit to the tdls_chandef so that the configuration here isn't
  446. * wider than what's actually requested on the channel context.
  447. */
  448. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  449. test_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW) &&
  450. test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
  451. sta->tdls_chandef.chan)
  452. bw = min(bw, ieee80211_chan_width_to_rx_bw(sta->tdls_chandef.width));
  453. else
  454. bw = min(bw, ieee80211_chan_width_to_rx_bw(bss_width));
  455. return bw;
  456. }
  457. void ieee80211_sta_set_rx_nss(struct link_sta_info *link_sta)
  458. {
  459. u8 ht_rx_nss = 0, vht_rx_nss = 0, he_rx_nss = 0, eht_rx_nss = 0, rx_nss;
  460. bool support_160;
  461. /* if we received a notification already don't overwrite it */
  462. if (link_sta->pub->rx_nss)
  463. return;
  464. if (link_sta->pub->eht_cap.has_eht) {
  465. int i;
  466. const u8 *rx_nss_mcs = (void *)&link_sta->pub->eht_cap.eht_mcs_nss_supp;
  467. /* get the max nss for EHT over all possible bandwidths and mcs */
  468. for (i = 0; i < sizeof(struct ieee80211_eht_mcs_nss_supp); i++)
  469. eht_rx_nss = max_t(u8, eht_rx_nss,
  470. u8_get_bits(rx_nss_mcs[i],
  471. IEEE80211_EHT_MCS_NSS_RX));
  472. }
  473. if (link_sta->pub->he_cap.has_he) {
  474. int i;
  475. u8 rx_mcs_80 = 0, rx_mcs_160 = 0;
  476. const struct ieee80211_sta_he_cap *he_cap = &link_sta->pub->he_cap;
  477. u16 mcs_160_map =
  478. le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160);
  479. u16 mcs_80_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80);
  480. for (i = 7; i >= 0; i--) {
  481. u8 mcs_160 = (mcs_160_map >> (2 * i)) & 3;
  482. if (mcs_160 != IEEE80211_HE_MCS_NOT_SUPPORTED) {
  483. rx_mcs_160 = i + 1;
  484. break;
  485. }
  486. }
  487. for (i = 7; i >= 0; i--) {
  488. u8 mcs_80 = (mcs_80_map >> (2 * i)) & 3;
  489. if (mcs_80 != IEEE80211_HE_MCS_NOT_SUPPORTED) {
  490. rx_mcs_80 = i + 1;
  491. break;
  492. }
  493. }
  494. support_160 = he_cap->he_cap_elem.phy_cap_info[0] &
  495. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
  496. if (support_160)
  497. he_rx_nss = min(rx_mcs_80, rx_mcs_160);
  498. else
  499. he_rx_nss = rx_mcs_80;
  500. }
  501. if (link_sta->pub->ht_cap.ht_supported) {
  502. if (link_sta->pub->ht_cap.mcs.rx_mask[0])
  503. ht_rx_nss++;
  504. if (link_sta->pub->ht_cap.mcs.rx_mask[1])
  505. ht_rx_nss++;
  506. if (link_sta->pub->ht_cap.mcs.rx_mask[2])
  507. ht_rx_nss++;
  508. if (link_sta->pub->ht_cap.mcs.rx_mask[3])
  509. ht_rx_nss++;
  510. /* FIXME: consider rx_highest? */
  511. }
  512. if (link_sta->pub->vht_cap.vht_supported) {
  513. int i;
  514. u16 rx_mcs_map;
  515. rx_mcs_map = le16_to_cpu(link_sta->pub->vht_cap.vht_mcs.rx_mcs_map);
  516. for (i = 7; i >= 0; i--) {
  517. u8 mcs = (rx_mcs_map >> (2 * i)) & 3;
  518. if (mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  519. vht_rx_nss = i + 1;
  520. break;
  521. }
  522. }
  523. /* FIXME: consider rx_highest? */
  524. }
  525. rx_nss = max(vht_rx_nss, ht_rx_nss);
  526. rx_nss = max(he_rx_nss, rx_nss);
  527. rx_nss = max(eht_rx_nss, rx_nss);
  528. link_sta->pub->rx_nss = max_t(u8, 1, rx_nss);
  529. }
  530. u32 __ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
  531. struct link_sta_info *link_sta,
  532. u8 opmode, enum nl80211_band band)
  533. {
  534. enum ieee80211_sta_rx_bandwidth new_bw;
  535. struct sta_opmode_info sta_opmode = {};
  536. u32 changed = 0;
  537. u8 nss;
  538. /* ignore - no support for BF yet */
  539. if (opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)
  540. return 0;
  541. nss = opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
  542. nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
  543. nss += 1;
  544. if (link_sta->pub->rx_nss != nss) {
  545. link_sta->pub->rx_nss = nss;
  546. sta_opmode.rx_nss = nss;
  547. changed |= IEEE80211_RC_NSS_CHANGED;
  548. sta_opmode.changed |= STA_OPMODE_N_SS_CHANGED;
  549. }
  550. switch (opmode & IEEE80211_OPMODE_NOTIF_CHANWIDTH_MASK) {
  551. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_20MHZ:
  552. /* ignore IEEE80211_OPMODE_NOTIF_BW_160_80P80 must not be set */
  553. link_sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_20;
  554. break;
  555. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_40MHZ:
  556. /* ignore IEEE80211_OPMODE_NOTIF_BW_160_80P80 must not be set */
  557. link_sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_40;
  558. break;
  559. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_80MHZ:
  560. if (opmode & IEEE80211_OPMODE_NOTIF_BW_160_80P80)
  561. link_sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
  562. else
  563. link_sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80;
  564. break;
  565. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_160MHZ:
  566. /* legacy only, no longer used by newer spec */
  567. link_sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
  568. break;
  569. }
  570. new_bw = ieee80211_sta_cur_vht_bw(link_sta);
  571. if (new_bw != link_sta->pub->bandwidth) {
  572. link_sta->pub->bandwidth = new_bw;
  573. sta_opmode.bw = ieee80211_sta_rx_bw_to_chan_width(link_sta);
  574. changed |= IEEE80211_RC_BW_CHANGED;
  575. sta_opmode.changed |= STA_OPMODE_MAX_BW_CHANGED;
  576. }
  577. if (sta_opmode.changed)
  578. cfg80211_sta_opmode_change_notify(sdata->dev, link_sta->addr,
  579. &sta_opmode, GFP_KERNEL);
  580. return changed;
  581. }
  582. void ieee80211_process_mu_groups(struct ieee80211_sub_if_data *sdata,
  583. struct ieee80211_link_data *link,
  584. struct ieee80211_mgmt *mgmt)
  585. {
  586. struct ieee80211_bss_conf *link_conf = link->conf;
  587. if (!link_conf->mu_mimo_owner)
  588. return;
  589. if (!memcmp(mgmt->u.action.u.vht_group_notif.position,
  590. link_conf->mu_group.position, WLAN_USER_POSITION_LEN) &&
  591. !memcmp(mgmt->u.action.u.vht_group_notif.membership,
  592. link_conf->mu_group.membership, WLAN_MEMBERSHIP_LEN))
  593. return;
  594. memcpy(link_conf->mu_group.membership,
  595. mgmt->u.action.u.vht_group_notif.membership,
  596. WLAN_MEMBERSHIP_LEN);
  597. memcpy(link_conf->mu_group.position,
  598. mgmt->u.action.u.vht_group_notif.position,
  599. WLAN_USER_POSITION_LEN);
  600. ieee80211_link_info_change_notify(sdata, link,
  601. BSS_CHANGED_MU_GROUPS);
  602. }
  603. void ieee80211_update_mu_groups(struct ieee80211_vif *vif, unsigned int link_id,
  604. const u8 *membership, const u8 *position)
  605. {
  606. struct ieee80211_bss_conf *link_conf;
  607. rcu_read_lock();
  608. link_conf = rcu_dereference(vif->link_conf[link_id]);
  609. if (!WARN_ON_ONCE(!link_conf || !link_conf->mu_mimo_owner)) {
  610. memcpy(link_conf->mu_group.membership, membership,
  611. WLAN_MEMBERSHIP_LEN);
  612. memcpy(link_conf->mu_group.position, position,
  613. WLAN_USER_POSITION_LEN);
  614. }
  615. rcu_read_unlock();
  616. }
  617. EXPORT_SYMBOL_GPL(ieee80211_update_mu_groups);
  618. void ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
  619. struct link_sta_info *link_sta,
  620. u8 opmode, enum nl80211_band band)
  621. {
  622. struct ieee80211_local *local = sdata->local;
  623. struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
  624. u32 changed = __ieee80211_vht_handle_opmode(sdata, link_sta,
  625. opmode, band);
  626. if (changed > 0) {
  627. ieee80211_recalc_min_chandef(sdata, link_sta->link_id);
  628. rate_control_rate_update(local, sband, link_sta->sta,
  629. link_sta->link_id, changed);
  630. }
  631. }
  632. void ieee80211_get_vht_mask_from_cap(__le16 vht_cap,
  633. u16 vht_mask[NL80211_VHT_NSS_MAX])
  634. {
  635. int i;
  636. u16 mask, cap = le16_to_cpu(vht_cap);
  637. for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
  638. mask = (cap >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  639. switch (mask) {
  640. case IEEE80211_VHT_MCS_SUPPORT_0_7:
  641. vht_mask[i] = 0x00FF;
  642. break;
  643. case IEEE80211_VHT_MCS_SUPPORT_0_8:
  644. vht_mask[i] = 0x01FF;
  645. break;
  646. case IEEE80211_VHT_MCS_SUPPORT_0_9:
  647. vht_mask[i] = 0x03FF;
  648. break;
  649. case IEEE80211_VHT_MCS_NOT_SUPPORTED:
  650. default:
  651. vht_mask[i] = 0;
  652. break;
  653. }
  654. }
  655. }