1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * HE handling 4 * 5 * Copyright(c) 2017 Intel Deutschland GmbH 6 * Copyright(c) 2019-2026 Intel Corporation 7 */ 8 9 #include "ieee80211_i.h" 10 #include "rate.h" 11 12 static void 13 ieee80211_update_from_he_6ghz_capa(const struct ieee80211_he_6ghz_capa *he_6ghz_capa, 14 struct link_sta_info *link_sta) 15 { 16 struct sta_info *sta = link_sta->sta; 17 enum ieee80211_smps_mode smps_mode; 18 19 if (sta->sdata->vif.type == NL80211_IFTYPE_AP || 20 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { 21 switch (le16_get_bits(he_6ghz_capa->capa, 22 IEEE80211_HE_6GHZ_CAP_SM_PS)) { 23 case WLAN_HT_CAP_SM_PS_INVALID: 24 case WLAN_HT_CAP_SM_PS_STATIC: 25 smps_mode = IEEE80211_SMPS_STATIC; 26 break; 27 case WLAN_HT_CAP_SM_PS_DYNAMIC: 28 smps_mode = IEEE80211_SMPS_DYNAMIC; 29 break; 30 case WLAN_HT_CAP_SM_PS_DISABLED: 31 smps_mode = IEEE80211_SMPS_OFF; 32 break; 33 } 34 35 link_sta->pub->smps_mode = smps_mode; 36 } else { 37 link_sta->pub->smps_mode = IEEE80211_SMPS_OFF; 38 } 39 40 switch (le16_get_bits(he_6ghz_capa->capa, 41 IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN)) { 42 case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454: 43 link_sta->pub->agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_11454; 44 break; 45 case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991: 46 link_sta->pub->agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_7991; 47 break; 48 case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895: 49 default: 50 link_sta->pub->agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_3895; 51 break; 52 } 53 54 ieee80211_sta_recalc_aggregates(&sta->sta); 55 56 link_sta->pub->he_6ghz_capa = *he_6ghz_capa; 57 } 58 59 static void ieee80211_he_mcs_disable(__le16 *he_mcs) 60 { 61 u32 i; 62 63 for (i = 0; i < 8; i++) 64 *he_mcs |= cpu_to_le16(IEEE80211_HE_MCS_NOT_SUPPORTED << i * 2); 65 } 66 67 static void ieee80211_he_mcs_intersection(__le16 *he_own_rx, __le16 *he_peer_rx, 68 __le16 *he_own_tx, __le16 *he_peer_tx) 69 { 70 u32 i; 71 u16 own_rx, own_tx, peer_rx, peer_tx; 72 73 for (i = 0; i < 8; i++) { 74 own_rx = le16_to_cpu(*he_own_rx); 75 own_rx = (own_rx >> i * 2) & IEEE80211_HE_MCS_NOT_SUPPORTED; 76 77 own_tx = le16_to_cpu(*he_own_tx); 78 own_tx = (own_tx >> i * 2) & IEEE80211_HE_MCS_NOT_SUPPORTED; 79 80 peer_rx = le16_to_cpu(*he_peer_rx); 81 peer_rx = (peer_rx >> i * 2) & IEEE80211_HE_MCS_NOT_SUPPORTED; 82 83 peer_tx = le16_to_cpu(*he_peer_tx); 84 peer_tx = (peer_tx >> i * 2) & IEEE80211_HE_MCS_NOT_SUPPORTED; 85 86 if (peer_tx != IEEE80211_HE_MCS_NOT_SUPPORTED) { 87 if (own_rx == IEEE80211_HE_MCS_NOT_SUPPORTED) 88 peer_tx = IEEE80211_HE_MCS_NOT_SUPPORTED; 89 else if (own_rx < peer_tx) 90 peer_tx = own_rx; 91 } 92 93 if (peer_rx != IEEE80211_HE_MCS_NOT_SUPPORTED) { 94 if (own_tx == IEEE80211_HE_MCS_NOT_SUPPORTED) 95 peer_rx = IEEE80211_HE_MCS_NOT_SUPPORTED; 96 else if (own_tx < peer_rx) 97 peer_rx = own_tx; 98 } 99 100 *he_peer_rx &= 101 ~cpu_to_le16(IEEE80211_HE_MCS_NOT_SUPPORTED << i * 2); 102 *he_peer_rx |= cpu_to_le16(peer_rx << i * 2); 103 104 *he_peer_tx &= 105 ~cpu_to_le16(IEEE80211_HE_MCS_NOT_SUPPORTED << i * 2); 106 *he_peer_tx |= cpu_to_le16(peer_tx << i * 2); 107 } 108 } 109 110 void 111 _ieee80211_he_cap_ie_to_sta_he_cap(struct ieee80211_sub_if_data *sdata, 112 const struct ieee80211_sta_he_cap *own_he_cap_ptr, 113 const u8 *he_cap_ie, u8 he_cap_len, 114 const struct ieee80211_he_6ghz_capa *he_6ghz_capa, 115 struct link_sta_info *link_sta) 116 { 117 struct ieee80211_sta_he_cap *he_cap = &link_sta->pub->he_cap; 118 struct ieee80211_sta_he_cap own_he_cap; 119 struct ieee80211_he_cap_elem *he_cap_ie_elem = (void *)he_cap_ie; 120 u8 he_ppe_size; 121 u8 mcs_nss_size; 122 u8 he_total_size; 123 bool own_160, peer_160, own_80p80, peer_80p80; 124 125 memset(he_cap, 0, sizeof(*he_cap)); 126 127 if (!he_cap_ie || !own_he_cap_ptr || !own_he_cap_ptr->has_he) 128 return; 129 130 /* NDI station are using the capabilities from the NMI station */ 131 if (WARN_ON_ONCE(sdata->vif.type == NL80211_IFTYPE_NAN_DATA)) 132 return; 133 134 own_he_cap = *own_he_cap_ptr; 135 136 /* Make sure size is OK */ 137 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap_ie_elem); 138 he_ppe_size = 139 ieee80211_he_ppe_size(he_cap_ie[sizeof(he_cap->he_cap_elem) + 140 mcs_nss_size], 141 he_cap_ie_elem->phy_cap_info); 142 he_total_size = sizeof(he_cap->he_cap_elem) + mcs_nss_size + 143 he_ppe_size; 144 if (he_cap_len < he_total_size) 145 return; 146 147 memcpy(&he_cap->he_cap_elem, he_cap_ie, sizeof(he_cap->he_cap_elem)); 148 149 /* HE Tx/Rx HE MCS NSS Support Field */ 150 memcpy(&he_cap->he_mcs_nss_supp, 151 &he_cap_ie[sizeof(he_cap->he_cap_elem)], mcs_nss_size); 152 153 /* Check if there are (optional) PPE Thresholds */ 154 if (he_cap->he_cap_elem.phy_cap_info[6] & 155 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) 156 memcpy(he_cap->ppe_thres, 157 &he_cap_ie[sizeof(he_cap->he_cap_elem) + mcs_nss_size], 158 he_ppe_size); 159 160 he_cap->has_he = true; 161 162 if (he_6ghz_capa) 163 ieee80211_update_from_he_6ghz_capa(he_6ghz_capa, link_sta); 164 165 ieee80211_he_mcs_intersection(&own_he_cap.he_mcs_nss_supp.rx_mcs_80, 166 &he_cap->he_mcs_nss_supp.rx_mcs_80, 167 &own_he_cap.he_mcs_nss_supp.tx_mcs_80, 168 &he_cap->he_mcs_nss_supp.tx_mcs_80); 169 170 own_160 = own_he_cap.he_cap_elem.phy_cap_info[0] & 171 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G; 172 peer_160 = he_cap->he_cap_elem.phy_cap_info[0] & 173 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G; 174 175 if (peer_160 && own_160) { 176 ieee80211_he_mcs_intersection(&own_he_cap.he_mcs_nss_supp.rx_mcs_160, 177 &he_cap->he_mcs_nss_supp.rx_mcs_160, 178 &own_he_cap.he_mcs_nss_supp.tx_mcs_160, 179 &he_cap->he_mcs_nss_supp.tx_mcs_160); 180 } else if (peer_160 && !own_160) { 181 ieee80211_he_mcs_disable(&he_cap->he_mcs_nss_supp.rx_mcs_160); 182 ieee80211_he_mcs_disable(&he_cap->he_mcs_nss_supp.tx_mcs_160); 183 he_cap->he_cap_elem.phy_cap_info[0] &= 184 ~IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G; 185 } 186 187 own_80p80 = own_he_cap.he_cap_elem.phy_cap_info[0] & 188 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G; 189 peer_80p80 = he_cap->he_cap_elem.phy_cap_info[0] & 190 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G; 191 192 if (peer_80p80 && own_80p80) { 193 ieee80211_he_mcs_intersection(&own_he_cap.he_mcs_nss_supp.rx_mcs_80p80, 194 &he_cap->he_mcs_nss_supp.rx_mcs_80p80, 195 &own_he_cap.he_mcs_nss_supp.tx_mcs_80p80, 196 &he_cap->he_mcs_nss_supp.tx_mcs_80p80); 197 } else if (peer_80p80 && !own_80p80) { 198 ieee80211_he_mcs_disable(&he_cap->he_mcs_nss_supp.rx_mcs_80p80); 199 ieee80211_he_mcs_disable(&he_cap->he_mcs_nss_supp.tx_mcs_80p80); 200 he_cap->he_cap_elem.phy_cap_info[0] &= 201 ~IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G; 202 } 203 } 204 205 void 206 ieee80211_he_cap_ie_to_sta_he_cap(struct ieee80211_sub_if_data *sdata, 207 struct ieee80211_supported_band *sband, 208 const u8 *he_cap_ie, u8 he_cap_len, 209 const struct ieee80211_he_6ghz_capa *he_6ghz_capa, 210 struct link_sta_info *link_sta) 211 { 212 const struct ieee80211_sta_he_cap *own_he_cap = 213 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif); 214 215 _ieee80211_he_cap_ie_to_sta_he_cap(sdata, own_he_cap, he_cap_ie, 216 he_cap_len, 217 (sband->band == NL80211_BAND_6GHZ) ? 218 he_6ghz_capa : NULL, 219 link_sta); 220 } 221 222 void 223 ieee80211_he_op_ie_to_bss_conf(struct ieee80211_vif *vif, 224 const struct ieee80211_he_operation *he_op_ie) 225 { 226 memset(&vif->bss_conf.he_oper, 0, sizeof(vif->bss_conf.he_oper)); 227 if (!he_op_ie) 228 return; 229 230 vif->bss_conf.he_oper.params = __le32_to_cpu(he_op_ie->he_oper_params); 231 vif->bss_conf.he_oper.nss_set = __le16_to_cpu(he_op_ie->he_mcs_nss_set); 232 } 233 234 void 235 ieee80211_he_spr_ie_to_bss_conf(struct ieee80211_vif *vif, 236 const struct ieee80211_he_spr *he_spr_ie_elem) 237 { 238 struct ieee80211_he_obss_pd *he_obss_pd = 239 &vif->bss_conf.he_obss_pd; 240 const u8 *data; 241 242 memset(he_obss_pd, 0, sizeof(*he_obss_pd)); 243 244 if (!he_spr_ie_elem) 245 return; 246 247 he_obss_pd->sr_ctrl = he_spr_ie_elem->he_sr_control; 248 data = he_spr_ie_elem->optional; 249 250 if (he_spr_ie_elem->he_sr_control & 251 IEEE80211_HE_SPR_NON_SRG_OFFSET_PRESENT) 252 he_obss_pd->non_srg_max_offset = *data++; 253 254 if (he_spr_ie_elem->he_sr_control & 255 IEEE80211_HE_SPR_SRG_INFORMATION_PRESENT) { 256 he_obss_pd->min_offset = *data++; 257 he_obss_pd->max_offset = *data++; 258 memcpy(he_obss_pd->bss_color_bitmap, data, 8); 259 data += 8; 260 memcpy(he_obss_pd->partial_bssid_bitmap, data, 8); 261 he_obss_pd->enable = true; 262 } 263 } 264 265 static void ieee80211_link_sta_rc_update_omi(struct ieee80211_link_data *link, 266 struct link_sta_info *link_sta) 267 { 268 struct ieee80211_sub_if_data *sdata = link->sdata; 269 struct ieee80211_supported_band *sband; 270 enum ieee80211_sta_rx_bandwidth new_bw; 271 enum nl80211_band band; 272 273 band = link->conf->chanreq.oper.chan->band; 274 sband = sdata->local->hw.wiphy->bands[band]; 275 276 new_bw = ieee80211_sta_current_bw(link_sta, &link->conf->chanreq.oper, 277 IEEE80211_STA_BW_TX_TO_STA); 278 if (link_sta->pub->bandwidth == new_bw) 279 return; 280 281 link_sta->pub->bandwidth = new_bw; 282 rate_control_rate_update(sdata->local, sband, link_sta, 283 IEEE80211_RC_BW_CHANGED); 284 } 285 286 bool ieee80211_prepare_rx_omi_bw(struct ieee80211_link_sta *pub_link_sta, 287 enum ieee80211_sta_rx_bandwidth bw) 288 { 289 struct sta_info *sta = container_of(pub_link_sta->sta, 290 struct sta_info, sta); 291 struct ieee80211_local *local = sta->sdata->local; 292 struct link_sta_info *link_sta = 293 sdata_dereference(sta->link[pub_link_sta->link_id], sta->sdata); 294 struct ieee80211_link_data *link = 295 sdata_dereference(sta->sdata->link[pub_link_sta->link_id], 296 sta->sdata); 297 struct ieee80211_chanctx_conf *conf; 298 struct ieee80211_chanctx *chanctx; 299 bool ret; 300 301 if (WARN_ON(!link || !link_sta || link_sta->pub != pub_link_sta)) 302 return false; 303 304 conf = sdata_dereference(link->conf->chanctx_conf, sta->sdata); 305 if (WARN_ON(!conf)) 306 return false; 307 308 trace_api_prepare_rx_omi_bw(local, sta->sdata, link_sta, bw); 309 310 chanctx = container_of(conf, typeof(*chanctx), conf); 311 312 if (link_sta->rx_omi_bw_staging == bw) { 313 ret = false; 314 goto trace; 315 } 316 317 /* must call this API in pairs */ 318 if (WARN_ON(link_sta->rx_omi_bw_tx != link_sta->rx_omi_bw_staging || 319 link_sta->rx_omi_bw_rx != link_sta->rx_omi_bw_staging)) { 320 ret = false; 321 goto trace; 322 } 323 324 if (bw < link_sta->rx_omi_bw_staging) { 325 link_sta->rx_omi_bw_tx = bw; 326 ieee80211_link_sta_rc_update_omi(link, link_sta); 327 } else { 328 link_sta->rx_omi_bw_rx = bw; 329 ieee80211_recalc_chanctx_min_def(local, chanctx); 330 } 331 332 link_sta->rx_omi_bw_staging = bw; 333 ret = true; 334 trace: 335 trace_api_return_bool(local, ret); 336 return ret; 337 } 338 EXPORT_SYMBOL_GPL(ieee80211_prepare_rx_omi_bw); 339 340 void ieee80211_finalize_rx_omi_bw(struct ieee80211_link_sta *pub_link_sta) 341 { 342 struct sta_info *sta = container_of(pub_link_sta->sta, 343 struct sta_info, sta); 344 struct ieee80211_local *local = sta->sdata->local; 345 struct link_sta_info *link_sta = 346 sdata_dereference(sta->link[pub_link_sta->link_id], sta->sdata); 347 struct ieee80211_link_data *link = 348 sdata_dereference(sta->sdata->link[pub_link_sta->link_id], 349 sta->sdata); 350 struct ieee80211_chanctx_conf *conf; 351 struct ieee80211_chanctx *chanctx; 352 353 if (WARN_ON(!link || !link_sta || link_sta->pub != pub_link_sta)) 354 return; 355 356 conf = sdata_dereference(link->conf->chanctx_conf, sta->sdata); 357 if (WARN_ON(!conf)) 358 return; 359 360 trace_api_finalize_rx_omi_bw(local, sta->sdata, link_sta); 361 362 chanctx = container_of(conf, typeof(*chanctx), conf); 363 364 if (link_sta->rx_omi_bw_tx != link_sta->rx_omi_bw_staging) { 365 /* rate control in finalize only when widening bandwidth */ 366 WARN_ON(link_sta->rx_omi_bw_tx > link_sta->rx_omi_bw_staging); 367 link_sta->rx_omi_bw_tx = link_sta->rx_omi_bw_staging; 368 ieee80211_link_sta_rc_update_omi(link, link_sta); 369 } 370 371 if (link_sta->rx_omi_bw_rx != link_sta->rx_omi_bw_staging) { 372 /* channel context in finalize only when narrowing bandwidth */ 373 WARN_ON(link_sta->rx_omi_bw_rx < link_sta->rx_omi_bw_staging); 374 link_sta->rx_omi_bw_rx = link_sta->rx_omi_bw_staging; 375 ieee80211_recalc_chanctx_min_def(local, chanctx); 376 } 377 378 trace_api_return_void(local); 379 } 380 EXPORT_SYMBOL_GPL(ieee80211_finalize_rx_omi_bw); 381