vht.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  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 - 2024 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. struct cfg80211_chan_def *chandef)
  299. {
  300. unsigned int link_id = link_sta->link_id;
  301. struct ieee80211_sub_if_data *sdata = link_sta->sta->sdata;
  302. struct ieee80211_sta_vht_cap *vht_cap = &link_sta->pub->vht_cap;
  303. struct ieee80211_sta_he_cap *he_cap = &link_sta->pub->he_cap;
  304. struct ieee80211_sta_eht_cap *eht_cap = &link_sta->pub->eht_cap;
  305. u32 cap_width;
  306. if (he_cap->has_he) {
  307. enum nl80211_band band;
  308. u8 info;
  309. if (chandef) {
  310. band = chandef->chan->band;
  311. } else {
  312. struct ieee80211_bss_conf *link_conf;
  313. rcu_read_lock();
  314. link_conf = rcu_dereference(sdata->vif.link_conf[link_id]);
  315. band = link_conf->chanreq.oper.chan->band;
  316. rcu_read_unlock();
  317. }
  318. if (eht_cap->has_eht && band == NL80211_BAND_6GHZ) {
  319. info = eht_cap->eht_cap_elem.phy_cap_info[0];
  320. if (info & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ)
  321. return IEEE80211_STA_RX_BW_320;
  322. }
  323. info = he_cap->he_cap_elem.phy_cap_info[0];
  324. if (band == NL80211_BAND_2GHZ) {
  325. if (info & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G)
  326. return IEEE80211_STA_RX_BW_40;
  327. return IEEE80211_STA_RX_BW_20;
  328. }
  329. if (info & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G ||
  330. info & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)
  331. return IEEE80211_STA_RX_BW_160;
  332. if (info & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G)
  333. return IEEE80211_STA_RX_BW_80;
  334. return IEEE80211_STA_RX_BW_20;
  335. }
  336. if (!vht_cap->vht_supported)
  337. return link_sta->pub->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  338. IEEE80211_STA_RX_BW_40 :
  339. IEEE80211_STA_RX_BW_20;
  340. cap_width = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  341. if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
  342. cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
  343. return IEEE80211_STA_RX_BW_160;
  344. /*
  345. * If this is non-zero, then it does support 160 MHz after all,
  346. * in one form or the other. We don't distinguish here (or even
  347. * above) between 160 and 80+80 yet.
  348. */
  349. if (vht_cap->cap & IEEE80211_VHT_CAP_EXT_NSS_BW_MASK)
  350. return IEEE80211_STA_RX_BW_160;
  351. return IEEE80211_STA_RX_BW_80;
  352. }
  353. enum nl80211_chan_width
  354. ieee80211_sta_cap_chan_bw(struct link_sta_info *link_sta)
  355. {
  356. struct ieee80211_sta_vht_cap *vht_cap = &link_sta->pub->vht_cap;
  357. u32 cap_width;
  358. if (!vht_cap->vht_supported) {
  359. if (!link_sta->pub->ht_cap.ht_supported)
  360. return NL80211_CHAN_WIDTH_20_NOHT;
  361. return link_sta->pub->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  362. NL80211_CHAN_WIDTH_40 : NL80211_CHAN_WIDTH_20;
  363. }
  364. cap_width = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  365. if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ)
  366. return NL80211_CHAN_WIDTH_160;
  367. else if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
  368. return NL80211_CHAN_WIDTH_80P80;
  369. return NL80211_CHAN_WIDTH_80;
  370. }
  371. enum nl80211_chan_width
  372. ieee80211_sta_rx_bw_to_chan_width(struct link_sta_info *link_sta)
  373. {
  374. enum ieee80211_sta_rx_bandwidth cur_bw =
  375. link_sta->pub->bandwidth;
  376. struct ieee80211_sta_vht_cap *vht_cap =
  377. &link_sta->pub->vht_cap;
  378. u32 cap_width;
  379. switch (cur_bw) {
  380. case IEEE80211_STA_RX_BW_20:
  381. if (!link_sta->pub->ht_cap.ht_supported)
  382. return NL80211_CHAN_WIDTH_20_NOHT;
  383. else
  384. return NL80211_CHAN_WIDTH_20;
  385. case IEEE80211_STA_RX_BW_40:
  386. return NL80211_CHAN_WIDTH_40;
  387. case IEEE80211_STA_RX_BW_80:
  388. return NL80211_CHAN_WIDTH_80;
  389. case IEEE80211_STA_RX_BW_160:
  390. cap_width =
  391. vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  392. if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ)
  393. return NL80211_CHAN_WIDTH_160;
  394. return NL80211_CHAN_WIDTH_80P80;
  395. default:
  396. return NL80211_CHAN_WIDTH_20;
  397. }
  398. }
  399. enum ieee80211_sta_rx_bandwidth
  400. ieee80211_chan_width_to_rx_bw(enum nl80211_chan_width width)
  401. {
  402. switch (width) {
  403. case NL80211_CHAN_WIDTH_20_NOHT:
  404. case NL80211_CHAN_WIDTH_20:
  405. return IEEE80211_STA_RX_BW_20;
  406. case NL80211_CHAN_WIDTH_40:
  407. return IEEE80211_STA_RX_BW_40;
  408. case NL80211_CHAN_WIDTH_80:
  409. return IEEE80211_STA_RX_BW_80;
  410. case NL80211_CHAN_WIDTH_160:
  411. case NL80211_CHAN_WIDTH_80P80:
  412. return IEEE80211_STA_RX_BW_160;
  413. case NL80211_CHAN_WIDTH_320:
  414. return IEEE80211_STA_RX_BW_320;
  415. default:
  416. WARN_ON_ONCE(1);
  417. return IEEE80211_STA_RX_BW_20;
  418. }
  419. }
  420. /* FIXME: rename/move - this deals with everything not just VHT */
  421. enum ieee80211_sta_rx_bandwidth
  422. _ieee80211_sta_cur_vht_bw(struct link_sta_info *link_sta,
  423. struct cfg80211_chan_def *chandef)
  424. {
  425. struct sta_info *sta = link_sta->sta;
  426. enum nl80211_chan_width bss_width;
  427. enum ieee80211_sta_rx_bandwidth bw;
  428. if (chandef) {
  429. bss_width = chandef->width;
  430. } else {
  431. struct ieee80211_bss_conf *link_conf;
  432. rcu_read_lock();
  433. link_conf = rcu_dereference(sta->sdata->vif.link_conf[link_sta->link_id]);
  434. if (WARN_ON_ONCE(!link_conf)) {
  435. rcu_read_unlock();
  436. return IEEE80211_STA_RX_BW_20;
  437. }
  438. bss_width = link_conf->chanreq.oper.width;
  439. rcu_read_unlock();
  440. }
  441. bw = _ieee80211_sta_cap_rx_bw(link_sta, chandef);
  442. bw = min(bw, link_sta->cur_max_bandwidth);
  443. /* Don't consider AP's bandwidth for TDLS peers, section 11.23.1 of
  444. * IEEE80211-2016 specification makes higher bandwidth operation
  445. * possible on the TDLS link if the peers have wider bandwidth
  446. * capability.
  447. *
  448. * However, in this case, and only if the TDLS peer is authorized,
  449. * limit to the tdls_chandef so that the configuration here isn't
  450. * wider than what's actually requested on the channel context.
  451. */
  452. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  453. test_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW) &&
  454. test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
  455. sta->tdls_chandef.chan)
  456. bw = min(bw, ieee80211_chan_width_to_rx_bw(sta->tdls_chandef.width));
  457. else
  458. bw = min(bw, ieee80211_chan_width_to_rx_bw(bss_width));
  459. return bw;
  460. }
  461. void ieee80211_sta_init_nss(struct link_sta_info *link_sta)
  462. {
  463. u8 ht_rx_nss = 0, vht_rx_nss = 0, he_rx_nss = 0, eht_rx_nss = 0, rx_nss;
  464. bool support_160;
  465. if (link_sta->pub->eht_cap.has_eht) {
  466. int i;
  467. const u8 *rx_nss_mcs = (void *)&link_sta->pub->eht_cap.eht_mcs_nss_supp;
  468. /* get the max nss for EHT over all possible bandwidths and mcs */
  469. for (i = 0; i < sizeof(struct ieee80211_eht_mcs_nss_supp); i++)
  470. eht_rx_nss = max_t(u8, eht_rx_nss,
  471. u8_get_bits(rx_nss_mcs[i],
  472. IEEE80211_EHT_MCS_NSS_RX));
  473. }
  474. if (link_sta->pub->he_cap.has_he) {
  475. int i;
  476. u8 rx_mcs_80 = 0, rx_mcs_160 = 0;
  477. const struct ieee80211_sta_he_cap *he_cap = &link_sta->pub->he_cap;
  478. u16 mcs_160_map =
  479. le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160);
  480. u16 mcs_80_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80);
  481. for (i = 7; i >= 0; i--) {
  482. u8 mcs_160 = (mcs_160_map >> (2 * i)) & 3;
  483. if (mcs_160 != IEEE80211_HE_MCS_NOT_SUPPORTED) {
  484. rx_mcs_160 = i + 1;
  485. break;
  486. }
  487. }
  488. for (i = 7; i >= 0; i--) {
  489. u8 mcs_80 = (mcs_80_map >> (2 * i)) & 3;
  490. if (mcs_80 != IEEE80211_HE_MCS_NOT_SUPPORTED) {
  491. rx_mcs_80 = i + 1;
  492. break;
  493. }
  494. }
  495. support_160 = he_cap->he_cap_elem.phy_cap_info[0] &
  496. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
  497. if (support_160)
  498. he_rx_nss = min(rx_mcs_80, rx_mcs_160);
  499. else
  500. he_rx_nss = rx_mcs_80;
  501. }
  502. if (link_sta->pub->ht_cap.ht_supported) {
  503. if (link_sta->pub->ht_cap.mcs.rx_mask[0])
  504. ht_rx_nss++;
  505. if (link_sta->pub->ht_cap.mcs.rx_mask[1])
  506. ht_rx_nss++;
  507. if (link_sta->pub->ht_cap.mcs.rx_mask[2])
  508. ht_rx_nss++;
  509. if (link_sta->pub->ht_cap.mcs.rx_mask[3])
  510. ht_rx_nss++;
  511. /* FIXME: consider rx_highest? */
  512. }
  513. if (link_sta->pub->vht_cap.vht_supported) {
  514. int i;
  515. u16 rx_mcs_map;
  516. rx_mcs_map = le16_to_cpu(link_sta->pub->vht_cap.vht_mcs.rx_mcs_map);
  517. for (i = 7; i >= 0; i--) {
  518. u8 mcs = (rx_mcs_map >> (2 * i)) & 3;
  519. if (mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  520. vht_rx_nss = i + 1;
  521. break;
  522. }
  523. }
  524. /* FIXME: consider rx_highest? */
  525. }
  526. rx_nss = max(vht_rx_nss, ht_rx_nss);
  527. rx_nss = max(he_rx_nss, rx_nss);
  528. rx_nss = max(eht_rx_nss, rx_nss);
  529. rx_nss = max_t(u8, 1, rx_nss);
  530. link_sta->capa_nss = rx_nss;
  531. /* that shouldn't be set yet, but we can handle it anyway */
  532. if (link_sta->op_mode_nss)
  533. link_sta->pub->rx_nss =
  534. min_t(u8, rx_nss, link_sta->op_mode_nss);
  535. else
  536. link_sta->pub->rx_nss = rx_nss;
  537. }
  538. u32 __ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
  539. struct link_sta_info *link_sta,
  540. u8 opmode, enum nl80211_band band)
  541. {
  542. enum ieee80211_sta_rx_bandwidth new_bw;
  543. struct sta_opmode_info sta_opmode = {};
  544. u32 changed = 0;
  545. u8 nss;
  546. /* ignore - no support for BF yet */
  547. if (opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)
  548. return 0;
  549. nss = opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
  550. nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
  551. nss += 1;
  552. if (link_sta->op_mode_nss != nss) {
  553. if (nss <= link_sta->capa_nss) {
  554. link_sta->op_mode_nss = nss;
  555. if (nss != link_sta->pub->rx_nss) {
  556. link_sta->pub->rx_nss = nss;
  557. changed |= IEEE80211_RC_NSS_CHANGED;
  558. sta_opmode.rx_nss = link_sta->pub->rx_nss;
  559. sta_opmode.changed |= STA_OPMODE_N_SS_CHANGED;
  560. }
  561. } else {
  562. pr_warn_ratelimited("Ignoring NSS change in VHT Operating Mode Notification from %pM with invalid nss %d",
  563. link_sta->pub->addr, nss);
  564. }
  565. }
  566. switch (opmode & IEEE80211_OPMODE_NOTIF_CHANWIDTH_MASK) {
  567. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_20MHZ:
  568. /* ignore IEEE80211_OPMODE_NOTIF_BW_160_80P80 must not be set */
  569. link_sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_20;
  570. break;
  571. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_40MHZ:
  572. /* ignore IEEE80211_OPMODE_NOTIF_BW_160_80P80 must not be set */
  573. link_sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_40;
  574. break;
  575. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_80MHZ:
  576. if (opmode & IEEE80211_OPMODE_NOTIF_BW_160_80P80)
  577. link_sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
  578. else
  579. link_sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80;
  580. break;
  581. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_160MHZ:
  582. /* legacy only, no longer used by newer spec */
  583. link_sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
  584. break;
  585. }
  586. new_bw = ieee80211_sta_cur_vht_bw(link_sta);
  587. if (new_bw != link_sta->pub->bandwidth) {
  588. link_sta->pub->bandwidth = new_bw;
  589. sta_opmode.bw = ieee80211_sta_rx_bw_to_chan_width(link_sta);
  590. changed |= IEEE80211_RC_BW_CHANGED;
  591. sta_opmode.changed |= STA_OPMODE_MAX_BW_CHANGED;
  592. }
  593. if (sta_opmode.changed)
  594. cfg80211_sta_opmode_change_notify(sdata->dev, link_sta->addr,
  595. &sta_opmode, GFP_KERNEL);
  596. return changed;
  597. }
  598. void ieee80211_process_mu_groups(struct ieee80211_sub_if_data *sdata,
  599. struct ieee80211_link_data *link,
  600. struct ieee80211_mgmt *mgmt)
  601. {
  602. struct ieee80211_bss_conf *link_conf = link->conf;
  603. if (!link_conf->mu_mimo_owner)
  604. return;
  605. if (!memcmp(mgmt->u.action.u.vht_group_notif.position,
  606. link_conf->mu_group.position, WLAN_USER_POSITION_LEN) &&
  607. !memcmp(mgmt->u.action.u.vht_group_notif.membership,
  608. link_conf->mu_group.membership, WLAN_MEMBERSHIP_LEN))
  609. return;
  610. memcpy(link_conf->mu_group.membership,
  611. mgmt->u.action.u.vht_group_notif.membership,
  612. WLAN_MEMBERSHIP_LEN);
  613. memcpy(link_conf->mu_group.position,
  614. mgmt->u.action.u.vht_group_notif.position,
  615. WLAN_USER_POSITION_LEN);
  616. ieee80211_link_info_change_notify(sdata, link,
  617. BSS_CHANGED_MU_GROUPS);
  618. }
  619. void ieee80211_update_mu_groups(struct ieee80211_vif *vif, unsigned int link_id,
  620. const u8 *membership, const u8 *position)
  621. {
  622. struct ieee80211_bss_conf *link_conf;
  623. rcu_read_lock();
  624. link_conf = rcu_dereference(vif->link_conf[link_id]);
  625. if (!WARN_ON_ONCE(!link_conf || !link_conf->mu_mimo_owner)) {
  626. memcpy(link_conf->mu_group.membership, membership,
  627. WLAN_MEMBERSHIP_LEN);
  628. memcpy(link_conf->mu_group.position, position,
  629. WLAN_USER_POSITION_LEN);
  630. }
  631. rcu_read_unlock();
  632. }
  633. EXPORT_SYMBOL_GPL(ieee80211_update_mu_groups);
  634. void ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
  635. struct link_sta_info *link_sta,
  636. u8 opmode, enum nl80211_band band)
  637. {
  638. struct ieee80211_local *local = sdata->local;
  639. struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
  640. u32 changed = __ieee80211_vht_handle_opmode(sdata, link_sta,
  641. opmode, band);
  642. if (changed > 0) {
  643. ieee80211_recalc_min_chandef(sdata, link_sta->link_id);
  644. rate_control_rate_update(local, sband, link_sta->sta,
  645. link_sta->link_id, changed);
  646. }
  647. }
  648. void ieee80211_get_vht_mask_from_cap(__le16 vht_cap,
  649. u16 vht_mask[NL80211_VHT_NSS_MAX])
  650. {
  651. int i;
  652. u16 mask, cap = le16_to_cpu(vht_cap);
  653. for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
  654. mask = (cap >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  655. switch (mask) {
  656. case IEEE80211_VHT_MCS_SUPPORT_0_7:
  657. vht_mask[i] = 0x00FF;
  658. break;
  659. case IEEE80211_VHT_MCS_SUPPORT_0_8:
  660. vht_mask[i] = 0x01FF;
  661. break;
  662. case IEEE80211_VHT_MCS_SUPPORT_0_9:
  663. vht_mask[i] = 0x03FF;
  664. break;
  665. case IEEE80211_VHT_MCS_NOT_SUPPORTED:
  666. default:
  667. vht_mask[i] = 0;
  668. break;
  669. }
  670. }
  671. }