1 // SPDX-License-Identifier: ISC 2 /* Copyright (C) 2023 MediaTek Inc. */ 3 4 #include <linux/etherdevice.h> 5 #include <linux/platform_device.h> 6 #include <linux/pci.h> 7 #include <linux/module.h> 8 #include <linux/ctype.h> 9 #include <net/ipv6.h> 10 #include "mt7925.h" 11 #include "mcu.h" 12 #include "mac.h" 13 14 static void 15 mt7925_init_he_caps(struct mt792x_phy *phy, enum nl80211_band band, 16 struct ieee80211_sband_iftype_data *data, 17 enum nl80211_iftype iftype) 18 { 19 struct ieee80211_sta_he_cap *he_cap = &data->he_cap; 20 struct ieee80211_he_cap_elem *he_cap_elem = &he_cap->he_cap_elem; 21 struct ieee80211_he_mcs_nss_supp *he_mcs = &he_cap->he_mcs_nss_supp; 22 int i, nss = hweight8(phy->mt76->antenna_mask); 23 u16 mcs_map = 0; 24 25 for (i = 0; i < 8; i++) { 26 if (i < nss) 27 mcs_map |= (IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2)); 28 else 29 mcs_map |= (IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2)); 30 } 31 32 he_cap->has_he = true; 33 34 he_cap_elem->mac_cap_info[0] = IEEE80211_HE_MAC_CAP0_HTC_HE; 35 he_cap_elem->mac_cap_info[3] = IEEE80211_HE_MAC_CAP3_OMI_CONTROL | 36 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3; 37 he_cap_elem->mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU; 38 39 if (band == NL80211_BAND_2GHZ) 40 he_cap_elem->phy_cap_info[0] = 41 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G; 42 else 43 he_cap_elem->phy_cap_info[0] = 44 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | 45 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G; 46 47 he_cap_elem->phy_cap_info[1] = 48 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD; 49 he_cap_elem->phy_cap_info[2] = 50 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US | 51 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | 52 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ | 53 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | 54 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO; 55 56 switch (iftype) { 57 case NL80211_IFTYPE_AP: 58 he_cap_elem->mac_cap_info[2] |= 59 IEEE80211_HE_MAC_CAP2_BSR; 60 he_cap_elem->mac_cap_info[4] |= 61 IEEE80211_HE_MAC_CAP4_BQR; 62 he_cap_elem->mac_cap_info[5] |= 63 IEEE80211_HE_MAC_CAP5_OM_CTRL_UL_MU_DATA_DIS_RX; 64 he_cap_elem->phy_cap_info[3] |= 65 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK | 66 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK; 67 he_cap_elem->phy_cap_info[6] |= 68 IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE | 69 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT; 70 he_cap_elem->phy_cap_info[9] |= 71 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU | 72 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU; 73 break; 74 case NL80211_IFTYPE_STATION: 75 he_cap_elem->mac_cap_info[1] |= 76 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US; 77 78 if (band == NL80211_BAND_2GHZ) 79 he_cap_elem->phy_cap_info[0] |= 80 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G; 81 else 82 he_cap_elem->phy_cap_info[0] |= 83 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G; 84 85 he_cap_elem->phy_cap_info[1] |= 86 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A | 87 IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US; 88 he_cap_elem->phy_cap_info[3] |= 89 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK | 90 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK; 91 he_cap_elem->phy_cap_info[4] |= 92 IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE | 93 IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4 | 94 IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_4; 95 he_cap_elem->phy_cap_info[5] |= 96 IEEE80211_HE_PHY_CAP5_NG16_SU_FEEDBACK | 97 IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK; 98 he_cap_elem->phy_cap_info[6] |= 99 IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_42_SU | 100 IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU | 101 IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB | 102 IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE | 103 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT; 104 he_cap_elem->phy_cap_info[7] |= 105 IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP | 106 IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI; 107 he_cap_elem->phy_cap_info[8] |= 108 IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G | 109 IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU | 110 IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU | 111 IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_484; 112 he_cap_elem->phy_cap_info[9] |= 113 IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM | 114 IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK | 115 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU | 116 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU | 117 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB | 118 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB; 119 break; 120 default: 121 break; 122 } 123 124 he_mcs->rx_mcs_80 = cpu_to_le16(mcs_map); 125 he_mcs->tx_mcs_80 = cpu_to_le16(mcs_map); 126 he_mcs->rx_mcs_160 = cpu_to_le16(mcs_map); 127 he_mcs->tx_mcs_160 = cpu_to_le16(mcs_map); 128 129 memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres)); 130 131 if (he_cap_elem->phy_cap_info[6] & 132 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 133 mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss); 134 } else { 135 he_cap_elem->phy_cap_info[9] |= 136 u8_encode_bits(IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US, 137 IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK); 138 } 139 140 if (band == NL80211_BAND_6GHZ) { 141 u16 cap = IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS | 142 IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS; 143 144 cap |= u16_encode_bits(IEEE80211_HT_MPDU_DENSITY_0_5, 145 IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START) | 146 u16_encode_bits(IEEE80211_VHT_MAX_AMPDU_1024K, 147 IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP) | 148 u16_encode_bits(IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454, 149 IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN); 150 151 data->he_6ghz_capa.capa = cpu_to_le16(cap); 152 } 153 } 154 155 static void 156 mt7925_init_eht_caps(struct mt792x_phy *phy, enum nl80211_band band, 157 struct ieee80211_sband_iftype_data *data) 158 { 159 struct ieee80211_sta_eht_cap *eht_cap = &data->eht_cap; 160 struct ieee80211_eht_cap_elem_fixed *eht_cap_elem = &eht_cap->eht_cap_elem; 161 struct ieee80211_eht_mcs_nss_supp *eht_nss = &eht_cap->eht_mcs_nss_supp; 162 enum nl80211_chan_width width = phy->mt76->chandef.width; 163 int nss = hweight8(phy->mt76->antenna_mask); 164 int sts = hweight16(phy->mt76->chainmask); 165 u8 val; 166 167 if (!phy->dev->has_eht) 168 return; 169 170 eht_cap->has_eht = true; 171 172 eht_cap_elem->mac_cap_info[0] = 173 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS | 174 IEEE80211_EHT_MAC_CAP0_OM_CONTROL; 175 176 eht_cap_elem->phy_cap_info[0] = 177 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI | 178 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER | 179 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE; 180 181 eht_cap_elem->phy_cap_info[0] |= 182 u8_encode_bits(u8_get_bits(sts - 1, BIT(0)), 183 IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK); 184 185 eht_cap_elem->phy_cap_info[1] = 186 u8_encode_bits(u8_get_bits(sts - 1, GENMASK(2, 1)), 187 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK) | 188 u8_encode_bits(sts - 1, 189 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK); 190 191 eht_cap_elem->phy_cap_info[2] = 192 u8_encode_bits(sts - 1, IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK) | 193 u8_encode_bits(sts - 1, IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK); 194 195 eht_cap_elem->phy_cap_info[3] = 196 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK | 197 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK | 198 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK | 199 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK | 200 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK | 201 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK | 202 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK; 203 204 eht_cap_elem->phy_cap_info[4] = 205 u8_encode_bits(min_t(int, sts - 1, 2), 206 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK); 207 208 eht_cap_elem->phy_cap_info[5] = 209 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK | 210 u8_encode_bits(IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US, 211 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK) | 212 u8_encode_bits(u8_get_bits(0x11, GENMASK(1, 0)), 213 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK); 214 215 val = width == NL80211_CHAN_WIDTH_160 ? 0x7 : 216 width == NL80211_CHAN_WIDTH_80 ? 0x3 : 0x1; 217 eht_cap_elem->phy_cap_info[6] = 218 u8_encode_bits(u8_get_bits(0x11, GENMASK(4, 2)), 219 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK) | 220 u8_encode_bits(val, IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK); 221 222 eht_cap_elem->phy_cap_info[7] = 223 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ | 224 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ | 225 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ | 226 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ; 227 228 val = u8_encode_bits(nss, IEEE80211_EHT_MCS_NSS_RX) | 229 u8_encode_bits(nss, IEEE80211_EHT_MCS_NSS_TX); 230 231 eht_nss->bw._80.rx_tx_mcs9_max_nss = val; 232 eht_nss->bw._80.rx_tx_mcs11_max_nss = val; 233 eht_nss->bw._80.rx_tx_mcs13_max_nss = val; 234 eht_nss->bw._160.rx_tx_mcs9_max_nss = val; 235 eht_nss->bw._160.rx_tx_mcs11_max_nss = val; 236 eht_nss->bw._160.rx_tx_mcs13_max_nss = val; 237 } 238 239 int mt7925_init_mlo_caps(struct mt792x_phy *phy) 240 { 241 struct wiphy *wiphy = phy->mt76->hw->wiphy; 242 static const u8 ext_capa_sta[] = { 243 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, 244 }; 245 static struct wiphy_iftype_ext_capab ext_capab[] = { 246 { 247 .iftype = NL80211_IFTYPE_STATION, 248 .extended_capabilities = ext_capa_sta, 249 .extended_capabilities_mask = ext_capa_sta, 250 .extended_capabilities_len = sizeof(ext_capa_sta), 251 }, 252 }; 253 254 if (!(phy->chip_cap & MT792x_CHIP_CAP_MLO_EVT_EN)) 255 return 0; 256 257 ext_capab[0].eml_capabilities = phy->eml_cap; 258 ext_capab[0].mld_capa_and_ops = 259 u16_encode_bits(1, IEEE80211_MLD_CAP_OP_MAX_SIMUL_LINKS); 260 261 wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO; 262 wiphy->iftype_ext_capab = ext_capab; 263 wiphy->num_iftype_ext_capab = ARRAY_SIZE(ext_capab); 264 265 return 0; 266 } 267 268 static void 269 __mt7925_set_stream_he_eht_caps(struct mt792x_phy *phy, 270 struct ieee80211_supported_band *sband, 271 enum nl80211_band band) 272 { 273 struct ieee80211_sband_iftype_data *data = phy->iftype[band]; 274 int i, n = 0; 275 276 for (i = 0; i < NUM_NL80211_IFTYPES; i++) { 277 switch (i) { 278 case NL80211_IFTYPE_STATION: 279 case NL80211_IFTYPE_AP: 280 break; 281 default: 282 continue; 283 } 284 285 data[n].types_mask = BIT(i); 286 mt7925_init_he_caps(phy, band, &data[n], i); 287 mt7925_init_eht_caps(phy, band, &data[n]); 288 289 n++; 290 } 291 292 _ieee80211_set_sband_iftype_data(sband, data, n); 293 } 294 295 void mt7925_set_stream_he_eht_caps(struct mt792x_phy *phy) 296 { 297 if (phy->mt76->cap.has_2ghz) 298 __mt7925_set_stream_he_eht_caps(phy, &phy->mt76->sband_2g.sband, 299 NL80211_BAND_2GHZ); 300 301 if (phy->mt76->cap.has_5ghz) 302 __mt7925_set_stream_he_eht_caps(phy, &phy->mt76->sband_5g.sband, 303 NL80211_BAND_5GHZ); 304 305 if (phy->mt76->cap.has_6ghz) 306 __mt7925_set_stream_he_eht_caps(phy, &phy->mt76->sband_6g.sband, 307 NL80211_BAND_6GHZ); 308 } 309 310 int __mt7925_start(struct mt792x_phy *phy) 311 { 312 struct mt76_phy *mphy = phy->mt76; 313 int err; 314 315 err = mt7925_mcu_set_channel_domain(mphy); 316 if (err) 317 return err; 318 319 err = mt7925_mcu_set_rts_thresh(phy, 0x92b); 320 if (err) 321 return err; 322 323 err = mt7925_set_tx_sar_pwr(mphy->hw, NULL); 324 if (err) 325 return err; 326 327 mt792x_mac_reset_counters(phy); 328 set_bit(MT76_STATE_RUNNING, &mphy->state); 329 330 ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work, 331 MT792x_WATCHDOG_TIME); 332 333 return 0; 334 } 335 EXPORT_SYMBOL_GPL(__mt7925_start); 336 337 static int mt7925_start(struct ieee80211_hw *hw) 338 { 339 struct mt792x_phy *phy = mt792x_hw_phy(hw); 340 int err; 341 342 mt792x_mutex_acquire(phy->dev); 343 err = __mt7925_start(phy); 344 mt792x_mutex_release(phy->dev); 345 346 return err; 347 } 348 349 static int mt7925_mac_link_bss_add(struct mt792x_dev *dev, 350 struct ieee80211_bss_conf *link_conf, 351 struct mt792x_link_sta *mlink) 352 { 353 struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); 354 struct ieee80211_vif *vif = link_conf->vif; 355 struct mt792x_vif *mvif = mconf->vif; 356 struct mt76_txq *mtxq; 357 int idx, ret = 0; 358 359 mconf->mt76.idx = __ffs64(~dev->mt76.vif_mask); 360 if (mconf->mt76.idx >= MT792x_MAX_INTERFACES) { 361 ret = -ENOSPC; 362 goto out; 363 } 364 365 mconf->mt76.omac_idx = ieee80211_vif_is_mld(vif) ? 366 0 : mconf->mt76.idx; 367 mconf->mt76.band_idx = 0xff; 368 mconf->mt76.wmm_idx = mconf->mt76.idx % MT76_CONNAC_MAX_WMM_SETS; 369 370 if (mvif->phy->mt76->chandef.chan->band != NL80211_BAND_2GHZ) 371 mconf->mt76.basic_rates_idx = MT792x_BASIC_RATES_TBL + 4; 372 else 373 mconf->mt76.basic_rates_idx = MT792x_BASIC_RATES_TBL; 374 375 ret = mt76_connac_mcu_uni_add_dev(&dev->mphy, link_conf, 376 &mlink->wcid, true); 377 if (ret) 378 goto out; 379 380 dev->mt76.vif_mask |= BIT_ULL(mconf->mt76.idx); 381 mvif->phy->omac_mask |= BIT_ULL(mconf->mt76.omac_idx); 382 383 idx = MT792x_WTBL_RESERVED - mconf->mt76.idx; 384 385 INIT_LIST_HEAD(&mlink->wcid.poll_list); 386 mlink->wcid.idx = idx; 387 mlink->wcid.phy_idx = mconf->mt76.band_idx; 388 mlink->wcid.hw_key_idx = -1; 389 mlink->wcid.tx_info |= MT_WCID_TX_INFO_SET; 390 mt76_wcid_init(&mlink->wcid); 391 392 mt7925_mac_wtbl_update(dev, idx, 393 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); 394 395 ewma_rssi_init(&mconf->rssi); 396 397 rcu_assign_pointer(dev->mt76.wcid[idx], &mlink->wcid); 398 if (vif->txq) { 399 mtxq = (struct mt76_txq *)vif->txq->drv_priv; 400 mtxq->wcid = idx; 401 } 402 403 out: 404 return ret; 405 } 406 407 static int 408 mt7925_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 409 { 410 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 411 struct mt792x_dev *dev = mt792x_hw_dev(hw); 412 struct mt792x_phy *phy = mt792x_hw_phy(hw); 413 int ret = 0; 414 415 mt792x_mutex_acquire(dev); 416 417 mvif->phy = phy; 418 mvif->bss_conf.vif = mvif; 419 mvif->sta.vif = mvif; 420 mvif->deflink_id = IEEE80211_LINK_UNSPECIFIED; 421 422 ret = mt7925_mac_link_bss_add(dev, &vif->bss_conf, &mvif->sta.deflink); 423 if (ret < 0) 424 goto out; 425 426 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER; 427 out: 428 mt792x_mutex_release(dev); 429 430 return ret; 431 } 432 433 static void mt7925_roc_iter(void *priv, u8 *mac, 434 struct ieee80211_vif *vif) 435 { 436 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 437 struct mt792x_phy *phy = priv; 438 439 mt7925_mcu_abort_roc(phy, &mvif->bss_conf, phy->roc_token_id); 440 } 441 442 void mt7925_roc_work(struct work_struct *work) 443 { 444 struct mt792x_phy *phy; 445 446 phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy, 447 roc_work); 448 449 if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state)) 450 return; 451 452 mt792x_mutex_acquire(phy->dev); 453 ieee80211_iterate_active_interfaces(phy->mt76->hw, 454 IEEE80211_IFACE_ITER_RESUME_ALL, 455 mt7925_roc_iter, phy); 456 mt792x_mutex_release(phy->dev); 457 ieee80211_remain_on_channel_expired(phy->mt76->hw); 458 } 459 460 static int mt7925_abort_roc(struct mt792x_phy *phy, 461 struct mt792x_bss_conf *mconf) 462 { 463 int err = 0; 464 465 del_timer_sync(&phy->roc_timer); 466 cancel_work_sync(&phy->roc_work); 467 468 mt792x_mutex_acquire(phy->dev); 469 if (test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state)) 470 err = mt7925_mcu_abort_roc(phy, mconf, phy->roc_token_id); 471 mt792x_mutex_release(phy->dev); 472 473 return err; 474 } 475 476 static int mt7925_set_roc(struct mt792x_phy *phy, 477 struct mt792x_bss_conf *mconf, 478 struct ieee80211_channel *chan, 479 int duration, 480 enum mt7925_roc_req type) 481 { 482 int err; 483 484 if (test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state)) 485 return -EBUSY; 486 487 phy->roc_grant = false; 488 489 err = mt7925_mcu_set_roc(phy, mconf, chan, duration, type, 490 ++phy->roc_token_id); 491 if (err < 0) { 492 clear_bit(MT76_STATE_ROC, &phy->mt76->state); 493 goto out; 494 } 495 496 if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, 4 * HZ)) { 497 mt7925_mcu_abort_roc(phy, mconf, phy->roc_token_id); 498 clear_bit(MT76_STATE_ROC, &phy->mt76->state); 499 err = -ETIMEDOUT; 500 } 501 502 out: 503 return err; 504 } 505 506 static int mt7925_set_mlo_roc(struct mt792x_phy *phy, 507 struct mt792x_bss_conf *mconf, 508 u16 sel_links) 509 { 510 int err; 511 512 if (WARN_ON_ONCE(test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state))) 513 return -EBUSY; 514 515 phy->roc_grant = false; 516 517 err = mt7925_mcu_set_mlo_roc(mconf, sel_links, 5, ++phy->roc_token_id); 518 if (err < 0) { 519 clear_bit(MT76_STATE_ROC, &phy->mt76->state); 520 goto out; 521 } 522 523 if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, 4 * HZ)) { 524 mt7925_mcu_abort_roc(phy, mconf, phy->roc_token_id); 525 clear_bit(MT76_STATE_ROC, &phy->mt76->state); 526 err = -ETIMEDOUT; 527 } 528 529 out: 530 return err; 531 } 532 533 static int mt7925_remain_on_channel(struct ieee80211_hw *hw, 534 struct ieee80211_vif *vif, 535 struct ieee80211_channel *chan, 536 int duration, 537 enum ieee80211_roc_type type) 538 { 539 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 540 struct mt792x_phy *phy = mt792x_hw_phy(hw); 541 int err; 542 543 mt792x_mutex_acquire(phy->dev); 544 err = mt7925_set_roc(phy, &mvif->bss_conf, 545 chan, duration, MT7925_ROC_REQ_ROC); 546 mt792x_mutex_release(phy->dev); 547 548 return err; 549 } 550 551 static int mt7925_cancel_remain_on_channel(struct ieee80211_hw *hw, 552 struct ieee80211_vif *vif) 553 { 554 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 555 struct mt792x_phy *phy = mt792x_hw_phy(hw); 556 557 return mt7925_abort_roc(phy, &mvif->bss_conf); 558 } 559 560 static int mt7925_set_link_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 561 struct ieee80211_vif *vif, struct ieee80211_sta *sta, 562 struct ieee80211_key_conf *key, int link_id) 563 { 564 struct mt792x_dev *dev = mt792x_hw_dev(hw); 565 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 566 struct mt792x_sta *msta = sta ? (struct mt792x_sta *)sta->drv_priv : 567 &mvif->sta; 568 struct ieee80211_bss_conf *link_conf; 569 struct ieee80211_link_sta *link_sta; 570 int idx = key->keyidx, err = 0; 571 struct mt792x_link_sta *mlink; 572 struct mt792x_bss_conf *mconf; 573 struct mt76_wcid *wcid; 574 u8 *wcid_keyidx; 575 576 link_conf = mt792x_vif_to_bss_conf(vif, link_id); 577 link_sta = sta ? mt792x_sta_to_link_sta(vif, sta, link_id) : NULL; 578 mconf = mt792x_vif_to_link(mvif, link_id); 579 mlink = mt792x_sta_to_link(msta, link_id); 580 wcid = &mlink->wcid; 581 wcid_keyidx = &wcid->hw_key_idx; 582 583 /* fall back to sw encryption for unsupported ciphers */ 584 switch (key->cipher) { 585 case WLAN_CIPHER_SUITE_AES_CMAC: 586 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE; 587 wcid_keyidx = &wcid->hw_key_idx2; 588 break; 589 case WLAN_CIPHER_SUITE_WEP40: 590 case WLAN_CIPHER_SUITE_WEP104: 591 if (!mvif->wep_sta) 592 return -EOPNOTSUPP; 593 break; 594 case WLAN_CIPHER_SUITE_TKIP: 595 case WLAN_CIPHER_SUITE_CCMP: 596 case WLAN_CIPHER_SUITE_CCMP_256: 597 case WLAN_CIPHER_SUITE_GCMP: 598 case WLAN_CIPHER_SUITE_GCMP_256: 599 case WLAN_CIPHER_SUITE_SMS4: 600 break; 601 default: 602 return -EOPNOTSUPP; 603 } 604 605 if (cmd == SET_KEY && !mconf->mt76.cipher) { 606 struct mt792x_phy *phy = mt792x_hw_phy(hw); 607 608 mconf->mt76.cipher = mt7925_mcu_get_cipher(key->cipher); 609 mt7925_mcu_add_bss_info(phy, mconf->mt76.ctx, link_conf, 610 link_sta, true); 611 } 612 613 if (cmd == SET_KEY) 614 *wcid_keyidx = idx; 615 else if (idx == *wcid_keyidx) 616 *wcid_keyidx = -1; 617 else 618 goto out; 619 620 mt76_wcid_key_setup(&dev->mt76, wcid, 621 cmd == SET_KEY ? key : NULL); 622 623 err = mt7925_mcu_add_key(&dev->mt76, vif, &mlink->bip, 624 key, MCU_UNI_CMD(STA_REC_UPDATE), 625 &mlink->wcid, cmd, msta); 626 627 if (err) 628 goto out; 629 630 if (key->cipher == WLAN_CIPHER_SUITE_WEP104 || 631 key->cipher == WLAN_CIPHER_SUITE_WEP40) 632 err = mt7925_mcu_add_key(&dev->mt76, vif, &mvif->wep_sta->deflink.bip, 633 key, MCU_WMWA_UNI_CMD(STA_REC_UPDATE), 634 &mvif->wep_sta->deflink.wcid, cmd, msta); 635 out: 636 return err; 637 } 638 639 static int mt7925_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 640 struct ieee80211_vif *vif, struct ieee80211_sta *sta, 641 struct ieee80211_key_conf *key) 642 { 643 struct mt792x_dev *dev = mt792x_hw_dev(hw); 644 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 645 struct mt792x_sta *msta = sta ? (struct mt792x_sta *)sta->drv_priv : 646 &mvif->sta; 647 int err; 648 649 /* The hardware does not support per-STA RX GTK, fallback 650 * to software mode for these. 651 */ 652 if ((vif->type == NL80211_IFTYPE_ADHOC || 653 vif->type == NL80211_IFTYPE_MESH_POINT) && 654 (key->cipher == WLAN_CIPHER_SUITE_TKIP || 655 key->cipher == WLAN_CIPHER_SUITE_CCMP) && 656 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) 657 return -EOPNOTSUPP; 658 659 mt792x_mutex_acquire(dev); 660 661 if (ieee80211_vif_is_mld(vif)) { 662 unsigned int link_id; 663 unsigned long add; 664 665 add = key->link_id != -1 ? BIT(key->link_id) : msta->valid_links; 666 667 for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) { 668 err = mt7925_set_link_key(hw, cmd, vif, sta, key, link_id); 669 if (err < 0) 670 break; 671 } 672 } else { 673 err = mt7925_set_link_key(hw, cmd, vif, sta, key, vif->bss_conf.link_id); 674 } 675 676 mt792x_mutex_release(dev); 677 678 return err; 679 } 680 681 static void 682 mt7925_pm_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif) 683 { 684 struct mt792x_dev *dev = priv; 685 struct ieee80211_hw *hw = mt76_hw(dev); 686 bool pm_enable = dev->pm.enable; 687 int err; 688 689 err = mt7925_mcu_set_beacon_filter(dev, vif, pm_enable); 690 if (err < 0) 691 return; 692 693 if (pm_enable) { 694 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER; 695 ieee80211_hw_set(hw, CONNECTION_MONITOR); 696 } else { 697 vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER; 698 __clear_bit(IEEE80211_HW_CONNECTION_MONITOR, hw->flags); 699 } 700 } 701 702 static void 703 mt7925_sniffer_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif) 704 { 705 struct mt792x_dev *dev = priv; 706 struct ieee80211_hw *hw = mt76_hw(dev); 707 struct mt76_connac_pm *pm = &dev->pm; 708 bool monitor = !!(hw->conf.flags & IEEE80211_CONF_MONITOR); 709 710 mt7925_mcu_set_sniffer(dev, vif, monitor); 711 pm->enable = pm->enable_user && !monitor; 712 pm->ds_enable = pm->ds_enable_user && !monitor; 713 714 mt7925_mcu_set_deep_sleep(dev, pm->ds_enable); 715 716 if (monitor) 717 mt7925_mcu_set_beacon_filter(dev, vif, false); 718 } 719 720 void mt7925_set_runtime_pm(struct mt792x_dev *dev) 721 { 722 struct ieee80211_hw *hw = mt76_hw(dev); 723 struct mt76_connac_pm *pm = &dev->pm; 724 bool monitor = !!(hw->conf.flags & IEEE80211_CONF_MONITOR); 725 726 pm->enable = pm->enable_user && !monitor; 727 ieee80211_iterate_active_interfaces(hw, 728 IEEE80211_IFACE_ITER_RESUME_ALL, 729 mt7925_pm_interface_iter, dev); 730 pm->ds_enable = pm->ds_enable_user && !monitor; 731 mt7925_mcu_set_deep_sleep(dev, pm->ds_enable); 732 } 733 734 static int mt7925_config(struct ieee80211_hw *hw, u32 changed) 735 { 736 struct mt792x_dev *dev = mt792x_hw_dev(hw); 737 int ret = 0; 738 739 mt792x_mutex_acquire(dev); 740 741 if (changed & IEEE80211_CONF_CHANGE_POWER) { 742 ret = mt7925_set_tx_sar_pwr(hw, NULL); 743 if (ret) 744 goto out; 745 } 746 747 if (changed & IEEE80211_CONF_CHANGE_MONITOR) { 748 ieee80211_iterate_active_interfaces(hw, 749 IEEE80211_IFACE_ITER_RESUME_ALL, 750 mt7925_sniffer_interface_iter, dev); 751 } 752 753 out: 754 mt792x_mutex_release(dev); 755 756 return ret; 757 } 758 759 static void mt7925_configure_filter(struct ieee80211_hw *hw, 760 unsigned int changed_flags, 761 unsigned int *total_flags, 762 u64 multicast) 763 { 764 #define MT7925_FILTER_FCSFAIL BIT(2) 765 #define MT7925_FILTER_CONTROL BIT(5) 766 #define MT7925_FILTER_OTHER_BSS BIT(6) 767 #define MT7925_FILTER_ENABLE BIT(31) 768 struct mt792x_dev *dev = mt792x_hw_dev(hw); 769 u32 flags = MT7925_FILTER_ENABLE; 770 771 #define MT7925_FILTER(_fif, _type) do { \ 772 if (*total_flags & (_fif)) \ 773 flags |= MT7925_FILTER_##_type; \ 774 } while (0) 775 776 MT7925_FILTER(FIF_FCSFAIL, FCSFAIL); 777 MT7925_FILTER(FIF_CONTROL, CONTROL); 778 MT7925_FILTER(FIF_OTHER_BSS, OTHER_BSS); 779 780 mt792x_mutex_acquire(dev); 781 mt7925_mcu_set_rxfilter(dev, flags, 0, 0); 782 mt792x_mutex_release(dev); 783 784 *total_flags &= (FIF_OTHER_BSS | FIF_FCSFAIL | FIF_CONTROL); 785 } 786 787 static u8 788 mt7925_get_rates_table(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 789 bool beacon, bool mcast) 790 { 791 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 792 struct mt76_phy *mphy = hw->priv; 793 u16 rate; 794 u8 i, idx, ht; 795 796 rate = mt76_connac2_mac_tx_rate_val(mphy, vif, beacon, mcast); 797 ht = FIELD_GET(MT_TX_RATE_MODE, rate) > MT_PHY_TYPE_OFDM; 798 799 if (beacon && ht) { 800 struct mt792x_dev *dev = mt792x_hw_dev(hw); 801 802 /* must odd index */ 803 idx = MT7925_BEACON_RATES_TBL + 2 * (mvif->idx % 20); 804 mt7925_mac_set_fixed_rate_table(dev, idx, rate); 805 return idx; 806 } 807 808 idx = FIELD_GET(MT_TX_RATE_IDX, rate); 809 for (i = 0; i < ARRAY_SIZE(mt76_rates); i++) 810 if ((mt76_rates[i].hw_value & GENMASK(7, 0)) == idx) 811 return MT792x_BASIC_RATES_TBL + i; 812 813 return mvif->basic_rates_idx; 814 } 815 816 static int mt7925_mac_link_sta_add(struct mt76_dev *mdev, 817 struct ieee80211_vif *vif, 818 struct ieee80211_link_sta *link_sta) 819 { 820 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); 821 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 822 struct ieee80211_bss_conf *link_conf; 823 struct mt792x_bss_conf *mconf; 824 u8 link_id = link_sta->link_id; 825 struct mt792x_link_sta *mlink; 826 struct mt792x_sta *msta; 827 int ret, idx; 828 829 msta = (struct mt792x_sta *)link_sta->sta->drv_priv; 830 mlink = mt792x_sta_to_link(msta, link_id); 831 832 idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT792x_WTBL_STA - 1); 833 if (idx < 0) 834 return -ENOSPC; 835 836 mconf = mt792x_vif_to_link(mvif, link_id); 837 INIT_LIST_HEAD(&mlink->wcid.poll_list); 838 mlink->wcid.sta = 1; 839 mlink->wcid.idx = idx; 840 mlink->wcid.phy_idx = mconf->mt76.band_idx; 841 mlink->wcid.tx_info |= MT_WCID_TX_INFO_SET; 842 mlink->last_txs = jiffies; 843 mlink->wcid.link_id = link_sta->link_id; 844 mlink->wcid.link_valid = !!link_sta->sta->valid_links; 845 846 ret = mt76_connac_pm_wake(&dev->mphy, &dev->pm); 847 if (ret) 848 return ret; 849 850 mt7925_mac_wtbl_update(dev, idx, 851 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); 852 853 link_conf = mt792x_vif_to_bss_conf(vif, link_id); 854 855 /* should update bss info before STA add */ 856 if (vif->type == NL80211_IFTYPE_STATION && !link_sta->sta->tdls) 857 mt7925_mcu_add_bss_info(&dev->phy, mconf->mt76.ctx, 858 link_conf, link_sta, false); 859 860 if (ieee80211_vif_is_mld(vif) && 861 link_sta == mlink->pri_link) { 862 ret = mt7925_mcu_sta_update(dev, link_sta, vif, true, 863 MT76_STA_INFO_STATE_NONE); 864 if (ret) 865 return ret; 866 } else if (ieee80211_vif_is_mld(vif) && 867 link_sta != mlink->pri_link) { 868 ret = mt7925_mcu_sta_update(dev, mlink->pri_link, vif, 869 true, MT76_STA_INFO_STATE_ASSOC); 870 if (ret) 871 return ret; 872 873 ret = mt7925_mcu_sta_update(dev, link_sta, vif, true, 874 MT76_STA_INFO_STATE_ASSOC); 875 if (ret) 876 return ret; 877 } else { 878 ret = mt7925_mcu_sta_update(dev, link_sta, vif, true, 879 MT76_STA_INFO_STATE_NONE); 880 if (ret) 881 return ret; 882 } 883 884 mt76_connac_power_save_sched(&dev->mphy, &dev->pm); 885 886 return 0; 887 } 888 889 static int 890 mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif, 891 struct ieee80211_sta *sta, unsigned long new_links) 892 { 893 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; 894 struct mt76_wcid *wcid; 895 unsigned int link_id; 896 int err = 0; 897 898 for_each_set_bit(link_id, &new_links, IEEE80211_MLD_MAX_NUM_LINKS) { 899 struct ieee80211_link_sta *link_sta; 900 struct mt792x_link_sta *mlink; 901 902 if (msta->deflink_id == IEEE80211_LINK_UNSPECIFIED) { 903 mlink = &msta->deflink; 904 msta->deflink_id = link_id; 905 } else { 906 mlink = devm_kzalloc(dev->mt76.dev, sizeof(*mlink), GFP_KERNEL); 907 if (!mlink) { 908 err = -ENOMEM; 909 break; 910 } 911 912 wcid = &mlink->wcid; 913 ewma_signal_init(&wcid->rssi); 914 rcu_assign_pointer(dev->mt76.wcid[wcid->idx], wcid); 915 mt76_wcid_init(wcid); 916 ewma_avg_signal_init(&mlink->avg_ack_signal); 917 memset(mlink->airtime_ac, 0, 918 sizeof(msta->deflink.airtime_ac)); 919 } 920 921 msta->valid_links |= BIT(link_id); 922 rcu_assign_pointer(msta->link[link_id], mlink); 923 mlink->sta = msta; 924 mlink->pri_link = &sta->deflink; 925 mlink->wcid.def_wcid = &msta->deflink.wcid; 926 927 link_sta = mt792x_sta_to_link_sta(vif, sta, link_id); 928 mt7925_mac_link_sta_add(&dev->mt76, vif, link_sta); 929 } 930 931 return err; 932 } 933 934 int mt7925_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, 935 struct ieee80211_sta *sta) 936 { 937 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); 938 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 939 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; 940 int err; 941 942 msta->vif = mvif; 943 944 if (vif->type == NL80211_IFTYPE_STATION) 945 mvif->wep_sta = msta; 946 947 if (ieee80211_vif_is_mld(vif)) { 948 msta->deflink_id = IEEE80211_LINK_UNSPECIFIED; 949 950 err = mt7925_mac_sta_add_links(dev, vif, sta, sta->valid_links); 951 } else { 952 err = mt7925_mac_link_sta_add(mdev, vif, &sta->deflink); 953 } 954 955 return err; 956 } 957 EXPORT_SYMBOL_GPL(mt7925_mac_sta_add); 958 959 static u16 960 mt7925_mac_select_links(struct mt76_dev *mdev, struct ieee80211_vif *vif) 961 { 962 unsigned long usable_links = ieee80211_vif_usable_links(vif); 963 struct { 964 u8 link_id; 965 enum nl80211_band band; 966 } data[IEEE80211_MLD_MAX_NUM_LINKS]; 967 u8 link_id, i, j, n_data = 0; 968 u16 sel_links = 0; 969 970 if (!ieee80211_vif_is_mld(vif)) 971 return 0; 972 973 if (vif->active_links == usable_links) 974 return vif->active_links; 975 976 rcu_read_lock(); 977 for_each_set_bit(link_id, &usable_links, IEEE80211_MLD_MAX_NUM_LINKS) { 978 struct ieee80211_bss_conf *link_conf = 979 rcu_dereference(vif->link_conf[link_id]); 980 981 if (WARN_ON_ONCE(!link_conf)) 982 continue; 983 984 data[n_data].link_id = link_id; 985 data[n_data].band = link_conf->chanreq.oper.chan->band; 986 n_data++; 987 } 988 rcu_read_unlock(); 989 990 for (i = 0; i < n_data; i++) { 991 if (!(BIT(data[i].link_id) & vif->active_links)) 992 continue; 993 994 sel_links = BIT(data[i].link_id); 995 996 for (j = 0; j < n_data; j++) { 997 if (data[i].band != data[j].band) { 998 sel_links |= BIT(data[j].link_id); 999 break; 1000 } 1001 } 1002 1003 break; 1004 } 1005 1006 return sel_links; 1007 } 1008 1009 static void 1010 mt7925_mac_set_links(struct mt76_dev *mdev, struct ieee80211_vif *vif) 1011 { 1012 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); 1013 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1014 struct ieee80211_bss_conf *link_conf = 1015 mt792x_vif_to_bss_conf(vif, mvif->deflink_id); 1016 struct cfg80211_chan_def *chandef = &link_conf->chanreq.oper; 1017 enum nl80211_band band = chandef->chan->band, secondary_band; 1018 1019 u16 sel_links = mt7925_mac_select_links(mdev, vif); 1020 u8 secondary_link_id = __ffs(~BIT(mvif->deflink_id) & sel_links); 1021 1022 if (!ieee80211_vif_is_mld(vif) || hweight16(sel_links) < 2) 1023 return; 1024 1025 link_conf = mt792x_vif_to_bss_conf(vif, secondary_link_id); 1026 secondary_band = link_conf->chanreq.oper.chan->band; 1027 1028 if (band == NL80211_BAND_2GHZ || 1029 (band == NL80211_BAND_5GHZ && secondary_band == NL80211_BAND_6GHZ)) { 1030 mt7925_abort_roc(mvif->phy, &mvif->bss_conf); 1031 1032 mt792x_mutex_acquire(dev); 1033 1034 mt7925_set_mlo_roc(mvif->phy, &mvif->bss_conf, sel_links); 1035 1036 mt792x_mutex_release(dev); 1037 } 1038 1039 ieee80211_set_active_links_async(vif, sel_links); 1040 } 1041 1042 static void mt7925_mac_link_sta_assoc(struct mt76_dev *mdev, 1043 struct ieee80211_vif *vif, 1044 struct ieee80211_link_sta *link_sta) 1045 { 1046 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); 1047 struct ieee80211_bss_conf *link_conf; 1048 struct mt792x_link_sta *mlink; 1049 struct mt792x_sta *msta; 1050 1051 msta = (struct mt792x_sta *)link_sta->sta->drv_priv; 1052 mlink = mt792x_sta_to_link(msta, link_sta->link_id); 1053 1054 mt792x_mutex_acquire(dev); 1055 1056 if (ieee80211_vif_is_mld(vif)) { 1057 link_conf = mt792x_vif_to_bss_conf(vif, msta->deflink_id); 1058 } else { 1059 link_conf = mt792x_vif_to_bss_conf(vif, vif->bss_conf.link_id); 1060 } 1061 1062 if (vif->type == NL80211_IFTYPE_STATION && !link_sta->sta->tdls) { 1063 struct mt792x_bss_conf *mconf; 1064 1065 mconf = mt792x_link_conf_to_mconf(link_conf); 1066 mt7925_mcu_add_bss_info(&dev->phy, mconf->mt76.ctx, 1067 link_conf, link_sta, true); 1068 } 1069 1070 ewma_avg_signal_init(&mlink->avg_ack_signal); 1071 1072 mt7925_mac_wtbl_update(dev, mlink->wcid.idx, 1073 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); 1074 memset(mlink->airtime_ac, 0, sizeof(mlink->airtime_ac)); 1075 1076 mt7925_mcu_sta_update(dev, link_sta, vif, true, MT76_STA_INFO_STATE_ASSOC); 1077 1078 mt792x_mutex_release(dev); 1079 } 1080 1081 void mt7925_mac_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif, 1082 struct ieee80211_sta *sta) 1083 { 1084 if (ieee80211_vif_is_mld(vif)) { 1085 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; 1086 struct ieee80211_link_sta *link_sta; 1087 1088 link_sta = mt792x_sta_to_link_sta(vif, sta, msta->deflink_id); 1089 1090 mt7925_mac_set_links(mdev, vif); 1091 1092 mt7925_mac_link_sta_assoc(mdev, vif, link_sta); 1093 } else { 1094 mt7925_mac_link_sta_assoc(mdev, vif, &sta->deflink); 1095 } 1096 } 1097 EXPORT_SYMBOL_GPL(mt7925_mac_sta_assoc); 1098 1099 static void mt7925_mac_link_sta_remove(struct mt76_dev *mdev, 1100 struct ieee80211_vif *vif, 1101 struct ieee80211_link_sta *link_sta) 1102 { 1103 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); 1104 struct ieee80211_bss_conf *link_conf; 1105 u8 link_id = link_sta->link_id; 1106 struct mt792x_link_sta *mlink; 1107 struct mt792x_sta *msta; 1108 1109 msta = (struct mt792x_sta *)link_sta->sta->drv_priv; 1110 mlink = mt792x_sta_to_link(msta, link_id); 1111 1112 mt76_connac_free_pending_tx_skbs(&dev->pm, &mlink->wcid); 1113 mt76_connac_pm_wake(&dev->mphy, &dev->pm); 1114 1115 mt7925_mcu_sta_update(dev, link_sta, vif, false, 1116 MT76_STA_INFO_STATE_NONE); 1117 mt7925_mac_wtbl_update(dev, mlink->wcid.idx, 1118 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); 1119 1120 link_conf = mt792x_vif_to_bss_conf(vif, link_id); 1121 1122 if (vif->type == NL80211_IFTYPE_STATION && !link_sta->sta->tdls) { 1123 struct mt792x_bss_conf *mconf; 1124 1125 mconf = mt792x_link_conf_to_mconf(link_conf); 1126 mt7925_mcu_add_bss_info(&dev->phy, mconf->mt76.ctx, link_conf, 1127 link_sta, false); 1128 } 1129 1130 spin_lock_bh(&mdev->sta_poll_lock); 1131 if (!list_empty(&mlink->wcid.poll_list)) 1132 list_del_init(&mlink->wcid.poll_list); 1133 spin_unlock_bh(&mdev->sta_poll_lock); 1134 1135 mt76_connac_power_save_sched(&dev->mphy, &dev->pm); 1136 } 1137 1138 static int 1139 mt7925_mac_sta_remove_links(struct mt792x_dev *dev, struct ieee80211_vif *vif, 1140 struct ieee80211_sta *sta, unsigned long old_links) 1141 { 1142 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; 1143 struct mt76_dev *mdev = &dev->mt76; 1144 struct mt76_wcid *wcid; 1145 unsigned int link_id; 1146 1147 for_each_set_bit(link_id, &old_links, IEEE80211_MLD_MAX_NUM_LINKS) { 1148 struct ieee80211_link_sta *link_sta; 1149 struct mt792x_link_sta *mlink; 1150 1151 link_sta = mt792x_sta_to_link_sta(vif, sta, link_id); 1152 if (!link_sta) 1153 continue; 1154 1155 mlink = mt792x_sta_to_link(msta, link_id); 1156 if (!mlink) 1157 continue; 1158 1159 mt7925_mac_link_sta_remove(&dev->mt76, vif, link_sta); 1160 1161 wcid = &mlink->wcid; 1162 rcu_assign_pointer(msta->link[link_id], NULL); 1163 msta->valid_links &= ~BIT(link_id); 1164 mlink->sta = NULL; 1165 mlink->pri_link = NULL; 1166 1167 if (link_sta != mlink->pri_link) { 1168 mt76_wcid_cleanup(mdev, wcid); 1169 mt76_wcid_mask_clear(mdev->wcid_mask, wcid->idx); 1170 mt76_wcid_mask_clear(mdev->wcid_phy_mask, wcid->idx); 1171 } 1172 1173 if (msta->deflink_id == link_id) 1174 msta->deflink_id = IEEE80211_LINK_UNSPECIFIED; 1175 } 1176 1177 return 0; 1178 } 1179 1180 void mt7925_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, 1181 struct ieee80211_sta *sta) 1182 { 1183 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); 1184 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; 1185 unsigned long rem; 1186 1187 rem = ieee80211_vif_is_mld(vif) ? msta->valid_links : BIT(0); 1188 1189 mt7925_mac_sta_remove_links(dev, vif, sta, rem); 1190 1191 if (vif->type == NL80211_IFTYPE_STATION) { 1192 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1193 1194 mvif->wep_sta = NULL; 1195 ewma_rssi_init(&mvif->bss_conf.rssi); 1196 } 1197 } 1198 EXPORT_SYMBOL_GPL(mt7925_mac_sta_remove); 1199 1200 static int mt7925_set_rts_threshold(struct ieee80211_hw *hw, u32 val) 1201 { 1202 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1203 1204 mt792x_mutex_acquire(dev); 1205 mt7925_mcu_set_rts_thresh(&dev->phy, val); 1206 mt792x_mutex_release(dev); 1207 1208 return 0; 1209 } 1210 1211 static int 1212 mt7925_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1213 struct ieee80211_ampdu_params *params) 1214 { 1215 enum ieee80211_ampdu_mlme_action action = params->action; 1216 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1217 struct ieee80211_sta *sta = params->sta; 1218 struct ieee80211_txq *txq = sta->txq[params->tid]; 1219 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; 1220 u16 tid = params->tid; 1221 u16 ssn = params->ssn; 1222 struct mt76_txq *mtxq; 1223 int ret = 0; 1224 1225 if (!txq) 1226 return -EINVAL; 1227 1228 mtxq = (struct mt76_txq *)txq->drv_priv; 1229 1230 mt792x_mutex_acquire(dev); 1231 switch (action) { 1232 case IEEE80211_AMPDU_RX_START: 1233 mt76_rx_aggr_start(&dev->mt76, &msta->deflink.wcid, tid, ssn, 1234 params->buf_size); 1235 mt7925_mcu_uni_rx_ba(dev, params, true); 1236 break; 1237 case IEEE80211_AMPDU_RX_STOP: 1238 mt76_rx_aggr_stop(&dev->mt76, &msta->deflink.wcid, tid); 1239 mt7925_mcu_uni_rx_ba(dev, params, false); 1240 break; 1241 case IEEE80211_AMPDU_TX_OPERATIONAL: 1242 mtxq->aggr = true; 1243 mtxq->send_bar = false; 1244 mt7925_mcu_uni_tx_ba(dev, params, true); 1245 break; 1246 case IEEE80211_AMPDU_TX_STOP_FLUSH: 1247 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 1248 mtxq->aggr = false; 1249 clear_bit(tid, &msta->deflink.wcid.ampdu_state); 1250 mt7925_mcu_uni_tx_ba(dev, params, false); 1251 break; 1252 case IEEE80211_AMPDU_TX_START: 1253 set_bit(tid, &msta->deflink.wcid.ampdu_state); 1254 ret = IEEE80211_AMPDU_TX_START_IMMEDIATE; 1255 break; 1256 case IEEE80211_AMPDU_TX_STOP_CONT: 1257 mtxq->aggr = false; 1258 clear_bit(tid, &msta->deflink.wcid.ampdu_state); 1259 mt7925_mcu_uni_tx_ba(dev, params, false); 1260 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); 1261 break; 1262 } 1263 mt792x_mutex_release(dev); 1264 1265 return ret; 1266 } 1267 1268 static bool is_valid_alpha2(const char *alpha2) 1269 { 1270 if (!alpha2) 1271 return false; 1272 1273 if (alpha2[0] == '0' && alpha2[1] == '0') 1274 return true; 1275 1276 if (isalpha(alpha2[0]) && isalpha(alpha2[1])) 1277 return true; 1278 1279 return false; 1280 } 1281 1282 void mt7925_scan_work(struct work_struct *work) 1283 { 1284 struct mt792x_phy *phy; 1285 1286 phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy, 1287 scan_work.work); 1288 1289 while (true) { 1290 struct mt76_dev *mdev = &phy->dev->mt76; 1291 struct sk_buff *skb; 1292 struct tlv *tlv; 1293 int tlv_len; 1294 1295 spin_lock_bh(&phy->dev->mt76.lock); 1296 skb = __skb_dequeue(&phy->scan_event_list); 1297 spin_unlock_bh(&phy->dev->mt76.lock); 1298 1299 if (!skb) 1300 break; 1301 1302 skb_pull(skb, sizeof(struct mt7925_mcu_rxd) + 4); 1303 tlv = (struct tlv *)skb->data; 1304 tlv_len = skb->len; 1305 1306 while (tlv_len > 0 && le16_to_cpu(tlv->len) <= tlv_len) { 1307 struct mt7925_mcu_scan_chinfo_event *evt; 1308 1309 switch (le16_to_cpu(tlv->tag)) { 1310 case UNI_EVENT_SCAN_DONE_BASIC: 1311 if (test_and_clear_bit(MT76_HW_SCANNING, &phy->mt76->state)) { 1312 struct cfg80211_scan_info info = { 1313 .aborted = false, 1314 }; 1315 ieee80211_scan_completed(phy->mt76->hw, &info); 1316 } 1317 break; 1318 case UNI_EVENT_SCAN_DONE_CHNLINFO: 1319 evt = (struct mt7925_mcu_scan_chinfo_event *)tlv->data; 1320 1321 if (!is_valid_alpha2(evt->alpha2)) 1322 break; 1323 1324 if (mdev->alpha2[0] != '0' && mdev->alpha2[1] != '0') 1325 break; 1326 1327 mt7925_mcu_set_clc(phy->dev, evt->alpha2, ENVIRON_INDOOR); 1328 1329 break; 1330 case UNI_EVENT_SCAN_DONE_NLO: 1331 ieee80211_sched_scan_results(phy->mt76->hw); 1332 break; 1333 default: 1334 break; 1335 } 1336 1337 tlv_len -= le16_to_cpu(tlv->len); 1338 tlv = (struct tlv *)((char *)(tlv) + le16_to_cpu(tlv->len)); 1339 } 1340 1341 dev_kfree_skb(skb); 1342 } 1343 } 1344 1345 static int 1346 mt7925_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1347 struct ieee80211_scan_request *req) 1348 { 1349 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1350 struct mt76_phy *mphy = hw->priv; 1351 int err; 1352 1353 mt792x_mutex_acquire(dev); 1354 err = mt7925_mcu_hw_scan(mphy, vif, req); 1355 mt792x_mutex_release(dev); 1356 1357 return err; 1358 } 1359 1360 static void 1361 mt7925_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 1362 { 1363 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1364 struct mt76_phy *mphy = hw->priv; 1365 1366 mt792x_mutex_acquire(dev); 1367 mt7925_mcu_cancel_hw_scan(mphy, vif); 1368 mt792x_mutex_release(dev); 1369 } 1370 1371 static int 1372 mt7925_start_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1373 struct cfg80211_sched_scan_request *req, 1374 struct ieee80211_scan_ies *ies) 1375 { 1376 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1377 struct mt76_phy *mphy = hw->priv; 1378 int err; 1379 1380 mt792x_mutex_acquire(dev); 1381 1382 err = mt7925_mcu_sched_scan_req(mphy, vif, req); 1383 if (err < 0) 1384 goto out; 1385 1386 err = mt7925_mcu_sched_scan_enable(mphy, vif, true); 1387 out: 1388 mt792x_mutex_release(dev); 1389 1390 return err; 1391 } 1392 1393 static int 1394 mt7925_stop_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 1395 { 1396 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1397 struct mt76_phy *mphy = hw->priv; 1398 int err; 1399 1400 mt792x_mutex_acquire(dev); 1401 err = mt7925_mcu_sched_scan_enable(mphy, vif, false); 1402 mt792x_mutex_release(dev); 1403 1404 return err; 1405 } 1406 1407 static int 1408 mt7925_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) 1409 { 1410 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1411 struct mt792x_phy *phy = mt792x_hw_phy(hw); 1412 int max_nss = hweight8(hw->wiphy->available_antennas_tx); 1413 1414 if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss) 1415 return -EINVAL; 1416 1417 if ((BIT(hweight8(tx_ant)) - 1) != tx_ant) 1418 tx_ant = BIT(ffs(tx_ant) - 1) - 1; 1419 1420 mt792x_mutex_acquire(dev); 1421 1422 phy->mt76->antenna_mask = tx_ant; 1423 phy->mt76->chainmask = tx_ant; 1424 1425 mt76_set_stream_caps(phy->mt76, true); 1426 mt7925_set_stream_he_eht_caps(phy); 1427 1428 /* TODO: update bmc_wtbl spe_idx when antenna changes */ 1429 mt792x_mutex_release(dev); 1430 1431 return 0; 1432 } 1433 1434 #ifdef CONFIG_PM 1435 static int mt7925_suspend(struct ieee80211_hw *hw, 1436 struct cfg80211_wowlan *wowlan) 1437 { 1438 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1439 struct mt792x_phy *phy = mt792x_hw_phy(hw); 1440 1441 cancel_delayed_work_sync(&phy->scan_work); 1442 cancel_delayed_work_sync(&phy->mt76->mac_work); 1443 1444 cancel_delayed_work_sync(&dev->pm.ps_work); 1445 mt76_connac_free_pending_tx_skbs(&dev->pm, NULL); 1446 1447 mt792x_mutex_acquire(dev); 1448 1449 clear_bit(MT76_STATE_RUNNING, &phy->mt76->state); 1450 ieee80211_iterate_active_interfaces(hw, 1451 IEEE80211_IFACE_ITER_RESUME_ALL, 1452 mt7925_mcu_set_suspend_iter, 1453 &dev->mphy); 1454 1455 mt792x_mutex_release(dev); 1456 1457 return 0; 1458 } 1459 1460 static int mt7925_resume(struct ieee80211_hw *hw) 1461 { 1462 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1463 struct mt792x_phy *phy = mt792x_hw_phy(hw); 1464 1465 mt792x_mutex_acquire(dev); 1466 1467 set_bit(MT76_STATE_RUNNING, &phy->mt76->state); 1468 ieee80211_iterate_active_interfaces(hw, 1469 IEEE80211_IFACE_ITER_RESUME_ALL, 1470 mt7925_mcu_set_suspend_iter, 1471 &dev->mphy); 1472 1473 ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work, 1474 MT792x_WATCHDOG_TIME); 1475 1476 mt792x_mutex_release(dev); 1477 1478 return 0; 1479 } 1480 1481 static void mt7925_set_rekey_data(struct ieee80211_hw *hw, 1482 struct ieee80211_vif *vif, 1483 struct cfg80211_gtk_rekey_data *data) 1484 { 1485 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1486 1487 mt792x_mutex_acquire(dev); 1488 mt76_connac_mcu_update_gtk_rekey(hw, vif, data); 1489 mt792x_mutex_release(dev); 1490 } 1491 #endif /* CONFIG_PM */ 1492 1493 static void mt7925_sta_set_decap_offload(struct ieee80211_hw *hw, 1494 struct ieee80211_vif *vif, 1495 struct ieee80211_sta *sta, 1496 bool enabled) 1497 { 1498 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; 1499 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1500 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1501 unsigned long valid = mvif->valid_links; 1502 u8 i; 1503 1504 mt792x_mutex_acquire(dev); 1505 1506 valid = ieee80211_vif_is_mld(vif) ? mvif->valid_links : BIT(0); 1507 1508 for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) { 1509 struct mt792x_link_sta *mlink; 1510 1511 mlink = mt792x_sta_to_link(msta, i); 1512 1513 if (enabled) 1514 set_bit(MT_WCID_FLAG_HDR_TRANS, &mlink->wcid.flags); 1515 else 1516 clear_bit(MT_WCID_FLAG_HDR_TRANS, &mlink->wcid.flags); 1517 1518 mt7925_mcu_wtbl_update_hdr_trans(dev, vif, sta, i); 1519 } 1520 1521 mt792x_mutex_release(dev); 1522 } 1523 1524 #if IS_ENABLED(CONFIG_IPV6) 1525 static void __mt7925_ipv6_addr_change(struct ieee80211_hw *hw, 1526 struct ieee80211_bss_conf *link_conf, 1527 struct inet6_dev *idev) 1528 { 1529 struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); 1530 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1531 struct inet6_ifaddr *ifa; 1532 struct sk_buff *skb; 1533 u8 idx = 0; 1534 1535 struct { 1536 struct { 1537 u8 bss_idx; 1538 u8 pad[3]; 1539 } __packed hdr; 1540 struct mt7925_arpns_tlv arpns; 1541 struct in6_addr ns_addrs[IEEE80211_BSS_ARP_ADDR_LIST_LEN]; 1542 } req_hdr = { 1543 .hdr = { 1544 .bss_idx = mconf->mt76.idx, 1545 }, 1546 .arpns = { 1547 .tag = cpu_to_le16(UNI_OFFLOAD_OFFLOAD_ND), 1548 .len = cpu_to_le16(sizeof(req_hdr) - 4), 1549 .enable = true, 1550 }, 1551 }; 1552 1553 read_lock_bh(&idev->lock); 1554 list_for_each_entry(ifa, &idev->addr_list, if_list) { 1555 if (ifa->flags & IFA_F_TENTATIVE) 1556 continue; 1557 req_hdr.ns_addrs[idx] = ifa->addr; 1558 if (++idx >= IEEE80211_BSS_ARP_ADDR_LIST_LEN) 1559 break; 1560 } 1561 read_unlock_bh(&idev->lock); 1562 1563 if (!idx) 1564 return; 1565 1566 req_hdr.arpns.ips_num = idx; 1567 1568 skb = __mt76_mcu_msg_alloc(&dev->mt76, NULL, sizeof(req_hdr), 1569 0, GFP_ATOMIC); 1570 if (!skb) 1571 return; 1572 1573 skb_put_data(skb, &req_hdr, sizeof(req_hdr)); 1574 1575 skb_queue_tail(&dev->ipv6_ns_list, skb); 1576 1577 ieee80211_queue_work(dev->mt76.hw, &dev->ipv6_ns_work); 1578 } 1579 1580 static void mt7925_ipv6_addr_change(struct ieee80211_hw *hw, 1581 struct ieee80211_vif *vif, 1582 struct inet6_dev *idev) 1583 { 1584 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1585 unsigned long valid = ieee80211_vif_is_mld(vif) ? 1586 mvif->valid_links : BIT(0); 1587 struct ieee80211_bss_conf *bss_conf; 1588 int i; 1589 1590 for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) { 1591 bss_conf = mt792x_vif_to_bss_conf(vif, i); 1592 __mt7925_ipv6_addr_change(hw, bss_conf, idev); 1593 } 1594 } 1595 1596 #endif 1597 1598 int mt7925_set_tx_sar_pwr(struct ieee80211_hw *hw, 1599 const struct cfg80211_sar_specs *sar) 1600 { 1601 struct mt76_phy *mphy = hw->priv; 1602 1603 if (sar) { 1604 int err = mt76_init_sar_power(hw, sar); 1605 1606 if (err) 1607 return err; 1608 } 1609 mt792x_init_acpi_sar_power(mt792x_hw_phy(hw), !sar); 1610 1611 return mt7925_mcu_set_rate_txpower(mphy); 1612 } 1613 1614 static int mt7925_set_sar_specs(struct ieee80211_hw *hw, 1615 const struct cfg80211_sar_specs *sar) 1616 { 1617 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1618 int err; 1619 1620 mt792x_mutex_acquire(dev); 1621 err = mt7925_mcu_set_clc(dev, dev->mt76.alpha2, 1622 dev->country_ie_env); 1623 if (err < 0) 1624 goto out; 1625 1626 err = mt7925_set_tx_sar_pwr(hw, sar); 1627 out: 1628 mt792x_mutex_release(dev); 1629 1630 return err; 1631 } 1632 1633 static void 1634 mt7925_channel_switch_beacon(struct ieee80211_hw *hw, 1635 struct ieee80211_vif *vif, 1636 struct cfg80211_chan_def *chandef) 1637 { 1638 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1639 1640 mt792x_mutex_acquire(dev); 1641 mt7925_mcu_uni_add_beacon_offload(dev, hw, vif, true); 1642 mt792x_mutex_release(dev); 1643 } 1644 1645 static int 1646 mt7925_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1647 unsigned int link_id, u16 queue, 1648 const struct ieee80211_tx_queue_params *params) 1649 { 1650 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1651 struct mt792x_bss_conf *mconf = mt792x_vif_to_link(mvif, link_id); 1652 static const u8 mq_to_aci[] = { 1653 [IEEE80211_AC_VO] = 3, 1654 [IEEE80211_AC_VI] = 2, 1655 [IEEE80211_AC_BE] = 0, 1656 [IEEE80211_AC_BK] = 1, 1657 }; 1658 1659 /* firmware uses access class index */ 1660 mconf->queue_params[mq_to_aci[queue]] = *params; 1661 1662 return 0; 1663 } 1664 1665 static int 1666 mt7925_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1667 struct ieee80211_bss_conf *link_conf) 1668 { 1669 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1670 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1671 int err; 1672 1673 mt792x_mutex_acquire(dev); 1674 1675 err = mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx, 1676 link_conf, NULL, true); 1677 if (err) 1678 goto out; 1679 1680 err = mt7925_mcu_set_bss_pm(dev, link_conf, true); 1681 if (err) 1682 goto out; 1683 1684 err = mt7925_mcu_sta_update(dev, NULL, vif, true, 1685 MT76_STA_INFO_STATE_NONE); 1686 out: 1687 mt792x_mutex_release(dev); 1688 1689 return err; 1690 } 1691 1692 static void 1693 mt7925_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1694 struct ieee80211_bss_conf *link_conf) 1695 { 1696 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1697 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1698 int err; 1699 1700 mt792x_mutex_acquire(dev); 1701 1702 err = mt7925_mcu_set_bss_pm(dev, link_conf, false); 1703 if (err) 1704 goto out; 1705 1706 mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx, link_conf, 1707 NULL, false); 1708 1709 out: 1710 mt792x_mutex_release(dev); 1711 } 1712 1713 static int 1714 mt7925_add_chanctx(struct ieee80211_hw *hw, 1715 struct ieee80211_chanctx_conf *ctx) 1716 { 1717 return 0; 1718 } 1719 1720 static void 1721 mt7925_remove_chanctx(struct ieee80211_hw *hw, 1722 struct ieee80211_chanctx_conf *ctx) 1723 { 1724 } 1725 1726 static void 1727 mt7925_change_chanctx(struct ieee80211_hw *hw, 1728 struct ieee80211_chanctx_conf *ctx, 1729 u32 changed) 1730 { 1731 struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv; 1732 struct mt792x_phy *phy = mt792x_hw_phy(hw); 1733 struct mt792x_bss_conf *mconf; 1734 struct ieee80211_vif *vif; 1735 struct mt792x_vif *mvif; 1736 1737 if (!mctx->bss_conf) 1738 return; 1739 1740 mconf = mctx->bss_conf; 1741 mvif = mconf->vif; 1742 vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv); 1743 1744 mt792x_mutex_acquire(phy->dev); 1745 if (vif->type == NL80211_IFTYPE_MONITOR) { 1746 mt7925_mcu_set_sniffer(mvif->phy->dev, vif, true); 1747 mt7925_mcu_config_sniffer(mvif, ctx); 1748 } else { 1749 if (ieee80211_vif_is_mld(vif)) { 1750 unsigned long valid = mvif->valid_links; 1751 u8 i; 1752 1753 for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) { 1754 mconf = mt792x_vif_to_link(mvif, i); 1755 if (mconf && mconf->mt76.ctx == ctx) 1756 break; 1757 } 1758 1759 } else { 1760 mconf = &mvif->bss_conf; 1761 } 1762 1763 if (mconf) { 1764 struct ieee80211_bss_conf *link_conf; 1765 1766 link_conf = mt792x_vif_to_bss_conf(vif, mconf->link_id); 1767 mt7925_mcu_set_chctx(mvif->phy->mt76, &mconf->mt76, 1768 link_conf, ctx); 1769 } 1770 } 1771 1772 mt792x_mutex_release(phy->dev); 1773 } 1774 1775 static void mt7925_mgd_prepare_tx(struct ieee80211_hw *hw, 1776 struct ieee80211_vif *vif, 1777 struct ieee80211_prep_tx_info *info) 1778 { 1779 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1780 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1781 u16 duration = info->duration ? info->duration : 1782 jiffies_to_msecs(HZ); 1783 1784 mt792x_mutex_acquire(dev); 1785 mt7925_set_roc(mvif->phy, &mvif->bss_conf, 1786 mvif->bss_conf.mt76.ctx->def.chan, duration, 1787 MT7925_ROC_REQ_JOIN); 1788 mt792x_mutex_release(dev); 1789 } 1790 1791 static void mt7925_mgd_complete_tx(struct ieee80211_hw *hw, 1792 struct ieee80211_vif *vif, 1793 struct ieee80211_prep_tx_info *info) 1794 { 1795 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1796 1797 mt7925_abort_roc(mvif->phy, &mvif->bss_conf); 1798 } 1799 1800 static void mt7925_vif_cfg_changed(struct ieee80211_hw *hw, 1801 struct ieee80211_vif *vif, 1802 u64 changed) 1803 { 1804 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1805 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1806 unsigned long valid = ieee80211_vif_is_mld(vif) ? 1807 mvif->valid_links : BIT(0); 1808 struct ieee80211_bss_conf *bss_conf; 1809 int i; 1810 1811 mt792x_mutex_acquire(dev); 1812 1813 if (changed & BSS_CHANGED_ASSOC) { 1814 mt7925_mcu_sta_update(dev, NULL, vif, true, 1815 MT76_STA_INFO_STATE_ASSOC); 1816 mt7925_mcu_set_beacon_filter(dev, vif, vif->cfg.assoc); 1817 } 1818 1819 if (changed & BSS_CHANGED_ARP_FILTER) { 1820 for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) { 1821 bss_conf = mt792x_vif_to_bss_conf(vif, i); 1822 mt7925_mcu_update_arp_filter(&dev->mt76, bss_conf); 1823 } 1824 } 1825 1826 if (changed & BSS_CHANGED_PS) { 1827 for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) { 1828 bss_conf = mt792x_vif_to_bss_conf(vif, i); 1829 mt7925_mcu_uni_bss_ps(dev, bss_conf); 1830 } 1831 } 1832 1833 mt792x_mutex_release(dev); 1834 } 1835 1836 static void mt7925_link_info_changed(struct ieee80211_hw *hw, 1837 struct ieee80211_vif *vif, 1838 struct ieee80211_bss_conf *info, 1839 u64 changed) 1840 { 1841 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1842 struct mt792x_phy *phy = mt792x_hw_phy(hw); 1843 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1844 struct mt792x_bss_conf *mconf; 1845 1846 mconf = mt792x_vif_to_link(mvif, info->link_id); 1847 1848 mt792x_mutex_acquire(dev); 1849 1850 if (changed & BSS_CHANGED_ERP_SLOT) { 1851 int slottime = info->use_short_slot ? 9 : 20; 1852 1853 if (slottime != phy->slottime) { 1854 phy->slottime = slottime; 1855 mt7925_mcu_set_timing(phy, info); 1856 } 1857 } 1858 1859 if (changed & BSS_CHANGED_MCAST_RATE) 1860 mconf->mt76.mcast_rates_idx = 1861 mt7925_get_rates_table(hw, vif, false, true); 1862 1863 if (changed & BSS_CHANGED_BASIC_RATES) 1864 mconf->mt76.basic_rates_idx = 1865 mt7925_get_rates_table(hw, vif, false, false); 1866 1867 if (changed & (BSS_CHANGED_BEACON | 1868 BSS_CHANGED_BEACON_ENABLED)) { 1869 mconf->mt76.beacon_rates_idx = 1870 mt7925_get_rates_table(hw, vif, true, false); 1871 1872 mt7925_mcu_uni_add_beacon_offload(dev, hw, vif, 1873 info->enable_beacon); 1874 } 1875 1876 /* ensure that enable txcmd_mode after bss_info */ 1877 if (changed & (BSS_CHANGED_QOS | BSS_CHANGED_BEACON_ENABLED)) 1878 mt7925_mcu_set_tx(dev, info); 1879 1880 mt792x_mutex_release(dev); 1881 } 1882 1883 static int 1884 mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1885 u16 old_links, u16 new_links, 1886 struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS]) 1887 { 1888 struct mt792x_bss_conf *mconfs[IEEE80211_MLD_MAX_NUM_LINKS] = {}, *mconf; 1889 struct mt792x_link_sta *mlinks[IEEE80211_MLD_MAX_NUM_LINKS] = {}, *mlink; 1890 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1891 unsigned long add = new_links & ~old_links; 1892 unsigned long rem = old_links & ~new_links; 1893 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1894 struct mt792x_phy *phy = mt792x_hw_phy(hw); 1895 struct ieee80211_bss_conf *link_conf; 1896 unsigned int link_id; 1897 int err; 1898 1899 if (old_links == new_links) 1900 return 0; 1901 1902 mt792x_mutex_acquire(dev); 1903 1904 for_each_set_bit(link_id, &rem, IEEE80211_MLD_MAX_NUM_LINKS) { 1905 mconf = mt792x_vif_to_link(mvif, link_id); 1906 mlink = mt792x_sta_to_link(&mvif->sta, link_id); 1907 1908 if (!mconf || !mlink) 1909 continue; 1910 1911 if (mconf != &mvif->bss_conf) { 1912 mt792x_mac_link_bss_remove(dev, mconf, mlink); 1913 devm_kfree(dev->mt76.dev, mconf); 1914 devm_kfree(dev->mt76.dev, mlink); 1915 } 1916 1917 rcu_assign_pointer(mvif->link_conf[link_id], NULL); 1918 rcu_assign_pointer(mvif->sta.link[link_id], NULL); 1919 } 1920 1921 for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) { 1922 if (!old_links) { 1923 mvif->deflink_id = link_id; 1924 mconf = &mvif->bss_conf; 1925 mlink = &mvif->sta.deflink; 1926 } else { 1927 mconf = devm_kzalloc(dev->mt76.dev, sizeof(*mconf), 1928 GFP_KERNEL); 1929 mlink = devm_kzalloc(dev->mt76.dev, sizeof(*mlink), 1930 GFP_KERNEL); 1931 } 1932 1933 mconfs[link_id] = mconf; 1934 mlinks[link_id] = mlink; 1935 mconf->link_id = link_id; 1936 mconf->vif = mvif; 1937 mlink->wcid.link_id = link_id; 1938 mlink->wcid.link_valid = !!vif->valid_links; 1939 mlink->wcid.def_wcid = &mvif->sta.deflink.wcid; 1940 } 1941 1942 if (hweight16(mvif->valid_links) == 0) 1943 mt792x_mac_link_bss_remove(dev, &mvif->bss_conf, 1944 &mvif->sta.deflink); 1945 1946 for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) { 1947 mconf = mconfs[link_id]; 1948 mlink = mlinks[link_id]; 1949 link_conf = mt792x_vif_to_bss_conf(vif, link_id); 1950 1951 rcu_assign_pointer(mvif->link_conf[link_id], mconf); 1952 rcu_assign_pointer(mvif->sta.link[link_id], mlink); 1953 1954 err = mt7925_mac_link_bss_add(dev, link_conf, mlink); 1955 if (err < 0) 1956 goto free; 1957 1958 if (mconf != &mvif->bss_conf) { 1959 err = mt7925_set_mlo_roc(phy, &mvif->bss_conf, 1960 vif->active_links); 1961 if (err < 0) 1962 goto free; 1963 } 1964 } 1965 1966 mvif->valid_links = new_links; 1967 1968 mt792x_mutex_release(dev); 1969 1970 return 0; 1971 1972 free: 1973 for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) { 1974 rcu_assign_pointer(mvif->link_conf[link_id], NULL); 1975 rcu_assign_pointer(mvif->sta.link[link_id], NULL); 1976 1977 if (mconf != &mvif->bss_conf) 1978 devm_kfree(dev->mt76.dev, mconfs[link_id]); 1979 if (mlink != &mvif->sta.deflink) 1980 devm_kfree(dev->mt76.dev, mlinks[link_id]); 1981 } 1982 1983 mt792x_mutex_release(dev); 1984 1985 return err; 1986 } 1987 1988 static int 1989 mt7925_change_sta_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1990 struct ieee80211_sta *sta, u16 old_links, u16 new_links) 1991 { 1992 unsigned long add = new_links & ~old_links; 1993 unsigned long rem = old_links & ~new_links; 1994 struct mt792x_dev *dev = mt792x_hw_dev(hw); 1995 int err = 0; 1996 1997 if (old_links == new_links) 1998 return 0; 1999 2000 mt792x_mutex_acquire(dev); 2001 2002 err = mt7925_mac_sta_remove_links(dev, vif, sta, rem); 2003 if (err < 0) 2004 goto out; 2005 2006 err = mt7925_mac_sta_add_links(dev, vif, sta, add); 2007 if (err < 0) 2008 goto out; 2009 2010 out: 2011 mt792x_mutex_release(dev); 2012 2013 return err; 2014 } 2015 2016 static int mt7925_assign_vif_chanctx(struct ieee80211_hw *hw, 2017 struct ieee80211_vif *vif, 2018 struct ieee80211_bss_conf *link_conf, 2019 struct ieee80211_chanctx_conf *ctx) 2020 { 2021 struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv; 2022 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 2023 struct mt792x_dev *dev = mt792x_hw_dev(hw); 2024 struct ieee80211_bss_conf *pri_link_conf; 2025 struct mt792x_bss_conf *mconf; 2026 2027 mutex_lock(&dev->mt76.mutex); 2028 2029 if (ieee80211_vif_is_mld(vif)) { 2030 mconf = mt792x_vif_to_link(mvif, link_conf->link_id); 2031 pri_link_conf = mt792x_vif_to_bss_conf(vif, mvif->deflink_id); 2032 2033 if (vif->type == NL80211_IFTYPE_STATION && 2034 mconf == &mvif->bss_conf) 2035 mt7925_mcu_add_bss_info(&dev->phy, NULL, pri_link_conf, 2036 NULL, true); 2037 } else { 2038 mconf = &mvif->bss_conf; 2039 } 2040 2041 mconf->mt76.ctx = ctx; 2042 mctx->bss_conf = mconf; 2043 mutex_unlock(&dev->mt76.mutex); 2044 2045 return 0; 2046 } 2047 2048 static void mt7925_unassign_vif_chanctx(struct ieee80211_hw *hw, 2049 struct ieee80211_vif *vif, 2050 struct ieee80211_bss_conf *link_conf, 2051 struct ieee80211_chanctx_conf *ctx) 2052 { 2053 struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv; 2054 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 2055 struct mt792x_dev *dev = mt792x_hw_dev(hw); 2056 struct ieee80211_bss_conf *pri_link_conf; 2057 struct mt792x_bss_conf *mconf; 2058 2059 mutex_lock(&dev->mt76.mutex); 2060 2061 if (ieee80211_vif_is_mld(vif)) { 2062 mconf = mt792x_vif_to_link(mvif, link_conf->link_id); 2063 pri_link_conf = mt792x_vif_to_bss_conf(vif, mvif->deflink_id); 2064 2065 if (vif->type == NL80211_IFTYPE_STATION && 2066 mconf == &mvif->bss_conf) 2067 mt7925_mcu_add_bss_info(&dev->phy, NULL, pri_link_conf, 2068 NULL, false); 2069 } else { 2070 mconf = &mvif->bss_conf; 2071 } 2072 2073 mctx->bss_conf = NULL; 2074 mconf->mt76.ctx = NULL; 2075 mutex_unlock(&dev->mt76.mutex); 2076 } 2077 2078 const struct ieee80211_ops mt7925_ops = { 2079 .tx = mt792x_tx, 2080 .start = mt7925_start, 2081 .stop = mt792x_stop, 2082 .add_interface = mt7925_add_interface, 2083 .remove_interface = mt792x_remove_interface, 2084 .config = mt7925_config, 2085 .conf_tx = mt7925_conf_tx, 2086 .configure_filter = mt7925_configure_filter, 2087 .start_ap = mt7925_start_ap, 2088 .stop_ap = mt7925_stop_ap, 2089 .sta_state = mt76_sta_state, 2090 .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove, 2091 .set_key = mt7925_set_key, 2092 .sta_set_decap_offload = mt7925_sta_set_decap_offload, 2093 #if IS_ENABLED(CONFIG_IPV6) 2094 .ipv6_addr_change = mt7925_ipv6_addr_change, 2095 #endif /* CONFIG_IPV6 */ 2096 .ampdu_action = mt7925_ampdu_action, 2097 .set_rts_threshold = mt7925_set_rts_threshold, 2098 .wake_tx_queue = mt76_wake_tx_queue, 2099 .release_buffered_frames = mt76_release_buffered_frames, 2100 .channel_switch_beacon = mt7925_channel_switch_beacon, 2101 .get_txpower = mt76_get_txpower, 2102 .get_stats = mt792x_get_stats, 2103 .get_et_sset_count = mt792x_get_et_sset_count, 2104 .get_et_strings = mt792x_get_et_strings, 2105 .get_et_stats = mt792x_get_et_stats, 2106 .get_tsf = mt792x_get_tsf, 2107 .set_tsf = mt792x_set_tsf, 2108 .get_survey = mt76_get_survey, 2109 .get_antenna = mt76_get_antenna, 2110 .set_antenna = mt7925_set_antenna, 2111 .set_coverage_class = mt792x_set_coverage_class, 2112 .hw_scan = mt7925_hw_scan, 2113 .cancel_hw_scan = mt7925_cancel_hw_scan, 2114 .sta_statistics = mt792x_sta_statistics, 2115 .sched_scan_start = mt7925_start_sched_scan, 2116 .sched_scan_stop = mt7925_stop_sched_scan, 2117 #ifdef CONFIG_PM 2118 .suspend = mt7925_suspend, 2119 .resume = mt7925_resume, 2120 .set_wakeup = mt792x_set_wakeup, 2121 .set_rekey_data = mt7925_set_rekey_data, 2122 #endif /* CONFIG_PM */ 2123 .flush = mt792x_flush, 2124 .set_sar_specs = mt7925_set_sar_specs, 2125 .remain_on_channel = mt7925_remain_on_channel, 2126 .cancel_remain_on_channel = mt7925_cancel_remain_on_channel, 2127 .add_chanctx = mt7925_add_chanctx, 2128 .remove_chanctx = mt7925_remove_chanctx, 2129 .change_chanctx = mt7925_change_chanctx, 2130 .assign_vif_chanctx = mt7925_assign_vif_chanctx, 2131 .unassign_vif_chanctx = mt7925_unassign_vif_chanctx, 2132 .mgd_prepare_tx = mt7925_mgd_prepare_tx, 2133 .mgd_complete_tx = mt7925_mgd_complete_tx, 2134 .vif_cfg_changed = mt7925_vif_cfg_changed, 2135 .link_info_changed = mt7925_link_info_changed, 2136 .change_vif_links = mt7925_change_vif_links, 2137 .change_sta_links = mt7925_change_sta_links, 2138 }; 2139 EXPORT_SYMBOL_GPL(mt7925_ops); 2140 2141 MODULE_AUTHOR("Deren Wu <deren.wu@mediatek.com>"); 2142 MODULE_DESCRIPTION("MediaTek MT7925 core driver"); 2143 MODULE_LICENSE("Dual BSD/GPL"); 2144