Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'mt76-for-kvalo-2025-01-14' of https://github.com/nbd168/wireless

mt76 patches for 6.14

- mlo fixes for mt792x
- single wiphy multiband support for mt7996
- mt7915 stability fixes

+3365 -1348
+1 -1
drivers/net/wireless/mediatek/mt76/Makefile
··· 10 10 11 11 mt76-y := \ 12 12 mmio.o util.o trace.o dma.o mac80211.o debugfs.o eeprom.o \ 13 - tx.o agg-rx.o mcu.o wed.o 13 + tx.o agg-rx.o mcu.o wed.o scan.o channel.o 14 14 15 15 mt76-$(CONFIG_PCI) += pci.o 16 16 mt76-$(CONFIG_NL80211_TESTMODE) += testmode.o
+406
drivers/net/wireless/mediatek/mt76/channel.c
··· 1 + // SPDX-License-Identifier: ISC 2 + /* 3 + * Copyright (C) 2024 Felix Fietkau <nbd@nbd.name> 4 + */ 5 + #include "mt76.h" 6 + 7 + static struct mt76_vif_link * 8 + mt76_alloc_mlink(struct mt76_dev *dev, struct mt76_vif_data *mvif) 9 + { 10 + struct mt76_vif_link *mlink; 11 + 12 + mlink = kzalloc(dev->drv->link_data_size, GFP_KERNEL); 13 + if (!mlink) 14 + return NULL; 15 + 16 + mlink->mvif = mvif; 17 + 18 + return mlink; 19 + } 20 + 21 + static int 22 + mt76_phy_update_channel(struct mt76_phy *phy, 23 + struct ieee80211_chanctx_conf *conf) 24 + { 25 + phy->radar_enabled = conf->radar_enabled; 26 + phy->main_chandef = conf->def; 27 + phy->chanctx = (struct mt76_chanctx *)conf->drv_priv; 28 + 29 + return __mt76_set_channel(phy, &phy->main_chandef, false); 30 + } 31 + 32 + int mt76_add_chanctx(struct ieee80211_hw *hw, 33 + struct ieee80211_chanctx_conf *conf) 34 + { 35 + struct mt76_chanctx *ctx = (struct mt76_chanctx *)conf->drv_priv; 36 + struct mt76_phy *phy = hw->priv; 37 + struct mt76_dev *dev = phy->dev; 38 + int ret = -EINVAL; 39 + 40 + phy = ctx->phy = dev->band_phys[conf->def.chan->band]; 41 + if (WARN_ON_ONCE(!phy)) 42 + return ret; 43 + 44 + if (dev->scan.phy == phy) 45 + mt76_abort_scan(dev); 46 + 47 + mutex_lock(&dev->mutex); 48 + if (!phy->chanctx) 49 + ret = mt76_phy_update_channel(phy, conf); 50 + else 51 + ret = 0; 52 + mutex_unlock(&dev->mutex); 53 + 54 + return ret; 55 + } 56 + EXPORT_SYMBOL_GPL(mt76_add_chanctx); 57 + 58 + void mt76_remove_chanctx(struct ieee80211_hw *hw, 59 + struct ieee80211_chanctx_conf *conf) 60 + { 61 + struct mt76_chanctx *ctx = (struct mt76_chanctx *)conf->drv_priv; 62 + struct mt76_phy *phy = hw->priv; 63 + struct mt76_dev *dev = phy->dev; 64 + 65 + phy = ctx->phy; 66 + if (WARN_ON_ONCE(!phy)) 67 + return; 68 + 69 + if (dev->scan.phy == phy) 70 + mt76_abort_scan(dev); 71 + 72 + mutex_lock(&dev->mutex); 73 + if (phy->chanctx == ctx) 74 + phy->chanctx = NULL; 75 + mutex_unlock(&dev->mutex); 76 + } 77 + EXPORT_SYMBOL_GPL(mt76_remove_chanctx); 78 + 79 + void mt76_change_chanctx(struct ieee80211_hw *hw, 80 + struct ieee80211_chanctx_conf *conf, 81 + u32 changed) 82 + { 83 + struct mt76_chanctx *ctx = (struct mt76_chanctx *)conf->drv_priv; 84 + struct mt76_phy *phy = ctx->phy; 85 + struct mt76_dev *dev = phy->dev; 86 + 87 + if (!(changed & (IEEE80211_CHANCTX_CHANGE_WIDTH | 88 + IEEE80211_CHANCTX_CHANGE_RADAR))) 89 + return; 90 + 91 + cancel_delayed_work_sync(&phy->mac_work); 92 + 93 + mutex_lock(&dev->mutex); 94 + mt76_phy_update_channel(phy, conf); 95 + mutex_unlock(&dev->mutex); 96 + } 97 + EXPORT_SYMBOL_GPL(mt76_change_chanctx); 98 + 99 + 100 + int mt76_assign_vif_chanctx(struct ieee80211_hw *hw, 101 + struct ieee80211_vif *vif, 102 + struct ieee80211_bss_conf *link_conf, 103 + struct ieee80211_chanctx_conf *conf) 104 + { 105 + struct mt76_chanctx *ctx = (struct mt76_chanctx *)conf->drv_priv; 106 + struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv; 107 + struct mt76_vif_data *mvif = mlink->mvif; 108 + int link_id = link_conf->link_id; 109 + struct mt76_phy *phy = ctx->phy; 110 + struct mt76_dev *dev = phy->dev; 111 + bool mlink_alloc = false; 112 + int ret = 0; 113 + 114 + if (dev->scan.vif == vif) 115 + mt76_abort_scan(dev); 116 + 117 + mutex_lock(&dev->mutex); 118 + 119 + if (vif->type == NL80211_IFTYPE_MONITOR && 120 + is_zero_ether_addr(vif->addr)) 121 + goto out; 122 + 123 + mlink = mt76_vif_conf_link(dev, vif, link_conf); 124 + if (!mlink) { 125 + mlink = mt76_alloc_mlink(dev, mvif); 126 + if (!mlink) { 127 + ret = -ENOMEM; 128 + goto out; 129 + } 130 + mlink_alloc = true; 131 + } 132 + 133 + mlink->ctx = conf; 134 + ret = dev->drv->vif_link_add(phy, vif, link_conf, mlink); 135 + if (ret) { 136 + if (mlink_alloc) 137 + kfree(mlink); 138 + goto out; 139 + } 140 + 141 + if (link_conf != &vif->bss_conf) 142 + rcu_assign_pointer(mvif->link[link_id], mlink); 143 + 144 + out: 145 + mutex_unlock(&dev->mutex); 146 + 147 + return ret; 148 + } 149 + EXPORT_SYMBOL_GPL(mt76_assign_vif_chanctx); 150 + 151 + void mt76_unassign_vif_chanctx(struct ieee80211_hw *hw, 152 + struct ieee80211_vif *vif, 153 + struct ieee80211_bss_conf *link_conf, 154 + struct ieee80211_chanctx_conf *conf) 155 + { 156 + struct mt76_chanctx *ctx = (struct mt76_chanctx *)conf->drv_priv; 157 + struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv; 158 + struct mt76_vif_data *mvif = mlink->mvif; 159 + int link_id = link_conf->link_id; 160 + struct mt76_phy *phy = ctx->phy; 161 + struct mt76_dev *dev = phy->dev; 162 + 163 + if (dev->scan.vif == vif) 164 + mt76_abort_scan(dev); 165 + 166 + mutex_lock(&dev->mutex); 167 + 168 + if (vif->type == NL80211_IFTYPE_MONITOR && 169 + is_zero_ether_addr(vif->addr)) 170 + goto out; 171 + 172 + mlink = mt76_vif_conf_link(dev, vif, link_conf); 173 + if (!mlink) 174 + goto out; 175 + 176 + if (link_conf != &vif->bss_conf) 177 + rcu_assign_pointer(mvif->link[link_id], NULL); 178 + 179 + dev->drv->vif_link_remove(phy, vif, link_conf, mlink); 180 + mlink->ctx = NULL; 181 + 182 + if (link_conf != &vif->bss_conf) 183 + kfree_rcu(mlink, rcu_head); 184 + 185 + out: 186 + mutex_unlock(&dev->mutex); 187 + } 188 + EXPORT_SYMBOL_GPL(mt76_unassign_vif_chanctx); 189 + 190 + int mt76_switch_vif_chanctx(struct ieee80211_hw *hw, 191 + struct ieee80211_vif_chanctx_switch *vifs, 192 + int n_vifs, 193 + enum ieee80211_chanctx_switch_mode mode) 194 + { 195 + struct mt76_chanctx *old_ctx = (struct mt76_chanctx *)vifs->old_ctx->drv_priv; 196 + struct mt76_chanctx *new_ctx = (struct mt76_chanctx *)vifs->new_ctx->drv_priv; 197 + struct ieee80211_chanctx_conf *conf = vifs->new_ctx; 198 + struct mt76_phy *old_phy = old_ctx->phy; 199 + struct mt76_phy *phy = hw->priv; 200 + struct mt76_dev *dev = phy->dev; 201 + struct mt76_vif_link *mlink; 202 + bool update_chan; 203 + int i, ret = 0; 204 + 205 + if (mode == CHANCTX_SWMODE_SWAP_CONTEXTS) 206 + phy = new_ctx->phy = dev->band_phys[conf->def.chan->band]; 207 + else 208 + phy = new_ctx->phy; 209 + if (!phy) 210 + return -EINVAL; 211 + 212 + update_chan = phy->chanctx != new_ctx; 213 + if (update_chan) { 214 + if (dev->scan.phy == phy) 215 + mt76_abort_scan(dev); 216 + 217 + cancel_delayed_work_sync(&phy->mac_work); 218 + } 219 + 220 + mutex_lock(&dev->mutex); 221 + 222 + if (mode == CHANCTX_SWMODE_SWAP_CONTEXTS && 223 + phy != old_phy && old_phy->chanctx == old_ctx) 224 + old_phy->chanctx = NULL; 225 + 226 + if (update_chan) 227 + ret = mt76_phy_update_channel(phy, vifs->new_ctx); 228 + 229 + if (ret) 230 + goto out; 231 + 232 + if (old_phy == phy) 233 + goto skip_link_replace; 234 + 235 + for (i = 0; i < n_vifs; i++) { 236 + mlink = mt76_vif_conf_link(dev, vifs[i].vif, vifs[i].link_conf); 237 + if (!mlink) 238 + continue; 239 + 240 + dev->drv->vif_link_remove(old_phy, vifs[i].vif, 241 + vifs[i].link_conf, mlink); 242 + 243 + ret = dev->drv->vif_link_add(phy, vifs[i].vif, 244 + vifs[i].link_conf, mlink); 245 + if (ret) 246 + goto out; 247 + 248 + } 249 + 250 + skip_link_replace: 251 + for (i = 0; i < n_vifs; i++) { 252 + mlink = mt76_vif_conf_link(dev, vifs[i].vif, vifs[i].link_conf); 253 + if (!mlink) 254 + continue; 255 + 256 + mlink->ctx = vifs->new_ctx; 257 + } 258 + 259 + out: 260 + mutex_unlock(&dev->mutex); 261 + 262 + return ret; 263 + } 264 + EXPORT_SYMBOL_GPL(mt76_switch_vif_chanctx); 265 + 266 + struct mt76_vif_link *mt76_get_vif_phy_link(struct mt76_phy *phy, 267 + struct ieee80211_vif *vif) 268 + { 269 + struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv; 270 + struct mt76_vif_data *mvif = mlink->mvif; 271 + struct mt76_dev *dev = phy->dev; 272 + int i, ret; 273 + 274 + for (i = 0; i < ARRAY_SIZE(mvif->link); i++) { 275 + mlink = mt76_dereference(mvif->link[i], dev); 276 + if (!mlink) 277 + continue; 278 + 279 + if (mt76_vif_link_phy(mlink) == phy) 280 + return mlink; 281 + } 282 + 283 + if (!dev->drv->vif_link_add) 284 + return ERR_PTR(-EINVAL); 285 + 286 + mlink = mt76_alloc_mlink(dev, mvif); 287 + if (!mlink) 288 + return ERR_PTR(-ENOMEM); 289 + 290 + mlink->offchannel = true; 291 + ret = dev->drv->vif_link_add(phy, vif, &vif->bss_conf, mlink); 292 + if (ret) { 293 + kfree(mlink); 294 + return ERR_PTR(ret); 295 + } 296 + 297 + return mlink; 298 + } 299 + 300 + void mt76_put_vif_phy_link(struct mt76_phy *phy, struct ieee80211_vif *vif, 301 + struct mt76_vif_link *mlink) 302 + { 303 + struct mt76_dev *dev = phy->dev; 304 + 305 + if (IS_ERR_OR_NULL(mlink) || !mlink->offchannel) 306 + return; 307 + 308 + dev->drv->vif_link_remove(phy, vif, &vif->bss_conf, mlink); 309 + kfree(mlink); 310 + } 311 + 312 + static void mt76_roc_complete(struct mt76_phy *phy) 313 + { 314 + struct mt76_vif_link *mlink = phy->roc_link; 315 + 316 + if (!phy->roc_vif) 317 + return; 318 + 319 + if (mlink) 320 + mlink->mvif->roc_phy = NULL; 321 + if (phy->main_chandef.chan) 322 + mt76_set_channel(phy, &phy->main_chandef, false); 323 + mt76_put_vif_phy_link(phy, phy->roc_vif, phy->roc_link); 324 + phy->roc_vif = NULL; 325 + phy->roc_link = NULL; 326 + ieee80211_remain_on_channel_expired(phy->hw); 327 + } 328 + 329 + void mt76_roc_complete_work(struct work_struct *work) 330 + { 331 + struct mt76_phy *phy = container_of(work, struct mt76_phy, roc_work.work); 332 + struct mt76_dev *dev = phy->dev; 333 + 334 + mutex_lock(&dev->mutex); 335 + mt76_roc_complete(phy); 336 + mutex_unlock(&dev->mutex); 337 + } 338 + 339 + void mt76_abort_roc(struct mt76_phy *phy) 340 + { 341 + struct mt76_dev *dev = phy->dev; 342 + 343 + cancel_delayed_work_sync(&phy->roc_work); 344 + 345 + mutex_lock(&dev->mutex); 346 + mt76_roc_complete(phy); 347 + mutex_unlock(&dev->mutex); 348 + } 349 + 350 + int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 351 + struct ieee80211_channel *chan, int duration, 352 + enum ieee80211_roc_type type) 353 + { 354 + struct cfg80211_chan_def chandef = {}; 355 + struct mt76_phy *phy = hw->priv; 356 + struct mt76_dev *dev = phy->dev; 357 + struct mt76_vif_link *mlink; 358 + int ret = 0; 359 + 360 + phy = dev->band_phys[chan->band]; 361 + if (!phy) 362 + return -EINVAL; 363 + 364 + mutex_lock(&dev->mutex); 365 + 366 + if (phy->roc_vif || dev->scan.phy == phy) { 367 + ret = -EBUSY; 368 + goto out; 369 + } 370 + 371 + mlink = mt76_get_vif_phy_link(phy, vif); 372 + if (IS_ERR(mlink)) { 373 + ret = PTR_ERR(mlink); 374 + goto out; 375 + } 376 + 377 + mlink->mvif->roc_phy = phy; 378 + phy->roc_vif = vif; 379 + phy->roc_link = mlink; 380 + cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_HT20); 381 + mt76_set_channel(phy, &chandef, true); 382 + ieee80211_ready_on_channel(hw); 383 + ieee80211_queue_delayed_work(phy->hw, &phy->roc_work, 384 + msecs_to_jiffies(duration)); 385 + 386 + out: 387 + mutex_unlock(&dev->mutex); 388 + return ret; 389 + } 390 + EXPORT_SYMBOL_GPL(mt76_remain_on_channel); 391 + 392 + int mt76_cancel_remain_on_channel(struct ieee80211_hw *hw, 393 + struct ieee80211_vif *vif) 394 + { 395 + struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv; 396 + struct mt76_vif_data *mvif = mlink->mvif; 397 + struct mt76_phy *phy = mvif->roc_phy; 398 + 399 + if (!phy) 400 + return 0; 401 + 402 + mt76_abort_roc(phy); 403 + 404 + return 0; 405 + } 406 + EXPORT_SYMBOL_GPL(mt76_cancel_remain_on_channel);
+17 -5
drivers/net/wireless/mediatek/mt76/dma.c
··· 631 631 return ret; 632 632 } 633 633 634 - int mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q, 634 + static int 635 + mt76_dma_rx_fill_buf(struct mt76_dev *dev, struct mt76_queue *q, 635 636 bool allow_direct) 636 637 { 637 638 int len = SKB_WITH_OVERHEAD(q->buf_size); ··· 640 639 641 640 if (!q->ndesc) 642 641 return 0; 643 - 644 - spin_lock_bh(&q->lock); 645 642 646 643 while (q->queued < q->ndesc - 1) { 647 644 struct mt76_queue_buf qbuf = {}; ··· 673 674 if (frames || mt76_queue_is_wed_rx(q)) 674 675 mt76_dma_kick_queue(dev, q); 675 676 677 + return frames; 678 + } 679 + 680 + int mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q, 681 + bool allow_direct) 682 + { 683 + int frames; 684 + 685 + if (!q->ndesc) 686 + return 0; 687 + 688 + spin_lock_bh(&q->lock); 689 + frames = mt76_dma_rx_fill_buf(dev, q, allow_direct); 676 690 spin_unlock_bh(&q->lock); 677 691 678 692 return frames; ··· 808 796 return; 809 797 810 798 mt76_dma_sync_idx(dev, q); 811 - mt76_dma_rx_fill(dev, q, false); 799 + mt76_dma_rx_fill_buf(dev, q, false); 812 800 } 813 801 814 802 static void ··· 981 969 982 970 mt76_for_each_q_rx(dev, i) { 983 971 netif_napi_add(dev->napi_dev, &dev->napi[i], poll); 984 - mt76_dma_rx_fill(dev, &dev->q_rx[i], false); 972 + mt76_dma_rx_fill_buf(dev, &dev->q_rx[i], false); 985 973 napi_enable(&dev->napi[i]); 986 974 } 987 975
+167 -69
drivers/net/wireless/mediatek/mt76/mac80211.c
··· 411 411 } 412 412 413 413 if (found) { 414 - phy->chandef.chan = &sband->channels[0]; 414 + cfg80211_chandef_create(&phy->chandef, &sband->channels[0], 415 + NL80211_CHAN_HT20); 415 416 phy->chan_state = &msband->chan[0]; 417 + phy->dev->band_phys[band] = phy; 416 418 return; 417 419 } 418 420 419 421 sband->n_channels = 0; 420 - phy->hw->wiphy->bands[band] = NULL; 422 + if (phy->hw->wiphy->bands[band] == sband) 423 + phy->hw->wiphy->bands[band] = NULL; 421 424 } 422 425 423 426 static int ··· 431 428 432 429 INIT_LIST_HEAD(&phy->tx_list); 433 430 spin_lock_init(&phy->tx_lock); 431 + INIT_DELAYED_WORK(&phy->roc_work, mt76_roc_complete_work); 432 + 433 + if ((void *)phy != hw->priv) 434 + return 0; 434 435 435 436 SET_IEEE80211_DEV(hw, dev->dev); 436 437 SET_IEEE80211_PERM_ADDR(hw, phy->macaddr); ··· 486 479 487 480 return 0; 488 481 } 482 + 483 + struct mt76_phy * 484 + mt76_alloc_radio_phy(struct mt76_dev *dev, unsigned int size, 485 + u8 band_idx) 486 + { 487 + struct ieee80211_hw *hw = dev->phy.hw; 488 + unsigned int phy_size; 489 + struct mt76_phy *phy; 490 + 491 + phy_size = ALIGN(sizeof(*phy), 8); 492 + phy = devm_kzalloc(dev->dev, size + phy_size, GFP_KERNEL); 493 + if (!phy) 494 + return NULL; 495 + 496 + phy->dev = dev; 497 + phy->hw = hw; 498 + phy->priv = (void *)phy + phy_size; 499 + phy->band_idx = band_idx; 500 + 501 + return phy; 502 + } 503 + EXPORT_SYMBOL_GPL(mt76_alloc_radio_phy); 489 504 490 505 struct mt76_phy * 491 506 mt76_alloc_phy(struct mt76_dev *dev, unsigned int size, ··· 581 552 mt76_check_sband(phy, &phy->sband_5g, NL80211_BAND_5GHZ); 582 553 mt76_check_sband(phy, &phy->sband_6g, NL80211_BAND_6GHZ); 583 554 584 - ret = ieee80211_register_hw(phy->hw); 585 - if (ret) 586 - return ret; 555 + if ((void *)phy == phy->hw->priv) { 556 + ret = ieee80211_register_hw(phy->hw); 557 + if (ret) 558 + return ret; 559 + } 587 560 588 561 set_bit(MT76_STATE_REGISTERED, &phy->state); 589 562 phy->dev->phys[phy->band_idx] = phy; ··· 721 690 INIT_LIST_HEAD(&dev->txwi_cache); 722 691 INIT_LIST_HEAD(&dev->rxwi_cache); 723 692 dev->token_size = dev->drv->token_size; 693 + INIT_DELAYED_WORK(&dev->scan_work, mt76_scan_work); 724 694 725 695 for (i = 0; i < ARRAY_SIZE(dev->q_rx); i++) 726 696 skb_queue_head_init(&dev->rx_skb[i]); ··· 744 712 int ret; 745 713 746 714 dev_set_drvdata(dev->dev, dev); 747 - mt76_wcid_init(&dev->global_wcid); 715 + mt76_wcid_init(&dev->global_wcid, phy->band_idx); 748 716 ret = mt76_phy_init(phy, hw); 749 717 if (ret) 750 718 return ret; ··· 815 783 ieee80211_free_hw(dev->hw); 816 784 } 817 785 EXPORT_SYMBOL_GPL(mt76_free_device); 786 + 787 + static struct mt76_phy * 788 + mt76_vif_phy(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 789 + { 790 + struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv; 791 + struct mt76_chanctx *ctx; 792 + 793 + if (!hw->wiphy->n_radio) 794 + return hw->priv; 795 + 796 + if (!mlink->ctx) 797 + return NULL; 798 + 799 + ctx = (struct mt76_chanctx *)mlink->ctx->drv_priv; 800 + return ctx->phy; 801 + } 818 802 819 803 static void mt76_rx_release_amsdu(struct mt76_phy *phy, enum mt76_rxq_id q) 820 804 { ··· 977 929 } 978 930 EXPORT_SYMBOL_GPL(mt76_update_survey); 979 931 980 - int mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef, 981 - bool offchannel) 932 + int __mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef, 933 + bool offchannel) 982 934 { 983 935 struct mt76_dev *dev = phy->dev; 984 936 int timeout = HZ / 5; 985 937 int ret; 986 938 987 - cancel_delayed_work_sync(&phy->mac_work); 988 - 989 - mutex_lock(&dev->mutex); 990 939 set_bit(MT76_RESET, &phy->state); 991 940 992 941 mt76_worker_disable(&dev->tx_worker); ··· 999 954 phy->offchannel = offchannel; 1000 955 1001 956 if (!offchannel) 1002 - phy->main_chan = chandef->chan; 957 + phy->main_chandef = *chandef; 1003 958 1004 - if (chandef->chan != phy->main_chan) 959 + if (chandef->chan != phy->main_chandef.chan) 1005 960 memset(phy->chan_state, 0, sizeof(*phy->chan_state)); 1006 - mt76_worker_enable(&dev->tx_worker); 1007 961 1008 962 ret = dev->drv->set_channel(phy); 1009 963 1010 964 clear_bit(MT76_RESET, &phy->state); 965 + mt76_worker_enable(&dev->tx_worker); 1011 966 mt76_worker_schedule(&dev->tx_worker); 1012 967 968 + return ret; 969 + } 970 + 971 + int mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef, 972 + bool offchannel) 973 + { 974 + struct mt76_dev *dev = phy->dev; 975 + int ret; 976 + 977 + cancel_delayed_work_sync(&phy->mac_work); 978 + 979 + mutex_lock(&dev->mutex); 980 + ret = __mt76_set_channel(phy, chandef, offchannel); 1013 981 mutex_unlock(&dev->mutex); 1014 982 1015 983 return ret; ··· 1034 976 struct cfg80211_chan_def *chandef = &hw->conf.chandef; 1035 977 bool offchannel = hw->conf.flags & IEEE80211_CONF_OFFCHANNEL; 1036 978 979 + phy->radar_enabled = hw->conf.radar_enabled; 980 + 1037 981 return mt76_set_channel(phy, chandef, offchannel); 1038 982 } 1039 983 EXPORT_SYMBOL_GPL(mt76_update_channel); 984 + 985 + static struct mt76_sband * 986 + mt76_get_survey_sband(struct mt76_phy *phy, int *idx) 987 + { 988 + if (*idx < phy->sband_2g.sband.n_channels) 989 + return &phy->sband_2g; 990 + 991 + *idx -= phy->sband_2g.sband.n_channels; 992 + if (*idx < phy->sband_5g.sband.n_channels) 993 + return &phy->sband_5g; 994 + 995 + *idx -= phy->sband_5g.sband.n_channels; 996 + if (*idx < phy->sband_6g.sband.n_channels) 997 + return &phy->sband_6g; 998 + 999 + *idx -= phy->sband_6g.sband.n_channels; 1000 + return NULL; 1001 + } 1040 1002 1041 1003 int mt76_get_survey(struct ieee80211_hw *hw, int idx, 1042 1004 struct survey_info *survey) 1043 1005 { 1044 1006 struct mt76_phy *phy = hw->priv; 1045 1007 struct mt76_dev *dev = phy->dev; 1046 - struct mt76_sband *sband; 1008 + struct mt76_sband *sband = NULL; 1047 1009 struct ieee80211_channel *chan; 1048 1010 struct mt76_channel_state *state; 1011 + int phy_idx = 0; 1049 1012 int ret = 0; 1050 1013 1051 1014 mutex_lock(&dev->mutex); 1052 - if (idx == 0 && dev->drv->update_survey) 1053 - mt76_update_survey(phy); 1054 1015 1055 - if (idx >= phy->sband_2g.sband.n_channels + 1056 - phy->sband_5g.sband.n_channels) { 1057 - idx -= (phy->sband_2g.sband.n_channels + 1058 - phy->sband_5g.sband.n_channels); 1059 - sband = &phy->sband_6g; 1060 - } else if (idx >= phy->sband_2g.sband.n_channels) { 1061 - idx -= phy->sband_2g.sband.n_channels; 1062 - sband = &phy->sband_5g; 1063 - } else { 1064 - sband = &phy->sband_2g; 1016 + for (phy_idx = 0; phy_idx < ARRAY_SIZE(dev->phys); phy_idx++) { 1017 + sband = NULL; 1018 + phy = dev->phys[phy_idx]; 1019 + if (!phy || phy->hw != hw) 1020 + continue; 1021 + 1022 + sband = mt76_get_survey_sband(phy, &idx); 1023 + 1024 + if (idx == 0 && phy->dev->drv->update_survey) 1025 + mt76_update_survey(phy); 1026 + 1027 + if (sband || !hw->wiphy->n_radio) 1028 + break; 1065 1029 } 1066 1030 1067 - if (idx >= sband->sband.n_channels) { 1031 + if (!sband) { 1068 1032 ret = -ENOENT; 1069 1033 goto out; 1070 1034 } ··· 1101 1021 if (state->noise) 1102 1022 survey->filled |= SURVEY_INFO_NOISE_DBM; 1103 1023 1104 - if (chan == phy->main_chan) { 1024 + if (chan == phy->main_chandef.chan) { 1105 1025 survey->filled |= SURVEY_INFO_IN_USE; 1106 1026 1107 1027 if (dev->drv->drv_flags & MT_DRV_SW_RX_AIRTIME) ··· 1542 1462 } 1543 1463 1544 1464 ewma_signal_init(&wcid->rssi); 1545 - if (phy->band_idx == MT_BAND1) 1546 - mt76_wcid_mask_set(dev->wcid_phy_mask, wcid->idx); 1547 - wcid->phy_idx = phy->band_idx; 1548 1465 rcu_assign_pointer(dev->wcid[wcid->idx], wcid); 1466 + phy->num_sta++; 1549 1467 1550 - mt76_wcid_init(wcid); 1468 + mt76_wcid_init(wcid, phy->band_idx); 1551 1469 out: 1552 1470 mutex_unlock(&dev->mutex); 1553 1471 1554 1472 return ret; 1555 1473 } 1556 1474 1557 - void __mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif, 1475 + void __mt76_sta_remove(struct mt76_phy *phy, struct ieee80211_vif *vif, 1558 1476 struct ieee80211_sta *sta) 1559 1477 { 1478 + struct mt76_dev *dev = phy->dev; 1560 1479 struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv; 1561 1480 int i, idx = wcid->idx; 1562 1481 ··· 1568 1489 mt76_wcid_cleanup(dev, wcid); 1569 1490 1570 1491 mt76_wcid_mask_clear(dev->wcid_mask, idx); 1571 - mt76_wcid_mask_clear(dev->wcid_phy_mask, idx); 1492 + phy->num_sta--; 1572 1493 } 1573 1494 EXPORT_SYMBOL_GPL(__mt76_sta_remove); 1574 1495 1575 1496 static void 1576 - mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif, 1497 + mt76_sta_remove(struct mt76_phy *phy, struct ieee80211_vif *vif, 1577 1498 struct ieee80211_sta *sta) 1578 1499 { 1500 + struct mt76_dev *dev = phy->dev; 1501 + 1579 1502 mutex_lock(&dev->mutex); 1580 - __mt76_sta_remove(dev, vif, sta); 1503 + __mt76_sta_remove(phy, vif, sta); 1581 1504 mutex_unlock(&dev->mutex); 1582 1505 } 1583 1506 ··· 1592 1511 struct mt76_dev *dev = phy->dev; 1593 1512 enum mt76_sta_event ev; 1594 1513 1514 + phy = mt76_vif_phy(hw, vif); 1515 + if (!phy) 1516 + return -EINVAL; 1517 + 1595 1518 if (old_state == IEEE80211_STA_NOTEXIST && 1596 1519 new_state == IEEE80211_STA_NONE) 1597 1520 return mt76_sta_add(phy, vif, sta); 1598 1521 1599 1522 if (old_state == IEEE80211_STA_NONE && 1600 1523 new_state == IEEE80211_STA_NOTEXIST) 1601 - mt76_sta_remove(dev, vif, sta); 1524 + mt76_sta_remove(phy, vif, sta); 1602 1525 1603 1526 if (!dev->drv->sta_event) 1604 1527 return 0; ··· 1638 1553 } 1639 1554 EXPORT_SYMBOL_GPL(mt76_sta_pre_rcu_remove); 1640 1555 1641 - void mt76_wcid_init(struct mt76_wcid *wcid) 1556 + void mt76_wcid_init(struct mt76_wcid *wcid, u8 band_idx) 1642 1557 { 1558 + wcid->hw_key_idx = -1; 1559 + wcid->phy_idx = band_idx; 1560 + 1643 1561 INIT_LIST_HEAD(&wcid->tx_list); 1644 1562 skb_queue_head_init(&wcid->tx_pending); 1645 1563 skb_queue_head_init(&wcid->tx_offchannel); 1646 1564 1647 1565 INIT_LIST_HEAD(&wcid->list); 1648 1566 idr_init(&wcid->pktid); 1567 + 1568 + INIT_LIST_HEAD(&wcid->poll_list); 1649 1569 } 1650 1570 EXPORT_SYMBOL_GPL(mt76_wcid_init); 1651 1571 ··· 1685 1595 } 1686 1596 EXPORT_SYMBOL_GPL(mt76_wcid_cleanup); 1687 1597 1598 + void mt76_wcid_add_poll(struct mt76_dev *dev, struct mt76_wcid *wcid) 1599 + { 1600 + if (test_bit(MT76_MCU_RESET, &dev->phy.state)) 1601 + return; 1602 + 1603 + spin_lock_bh(&dev->sta_poll_lock); 1604 + if (list_empty(&wcid->poll_list)) 1605 + list_add_tail(&wcid->poll_list, &dev->sta_poll_list); 1606 + spin_unlock_bh(&dev->sta_poll_lock); 1607 + } 1608 + EXPORT_SYMBOL_GPL(mt76_wcid_add_poll); 1609 + 1688 1610 int mt76_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1689 1611 unsigned int link_id, int *dbm) 1690 1612 { 1691 - struct mt76_phy *phy = hw->priv; 1692 - int n_chains = hweight16(phy->chainmask); 1693 - int delta = mt76_tx_power_nss_delta(n_chains); 1613 + struct mt76_phy *phy = mt76_vif_phy(hw, vif); 1614 + int n_chains, delta; 1694 1615 1616 + if (!phy) 1617 + return -EINVAL; 1618 + 1619 + n_chains = hweight16(phy->chainmask); 1620 + delta = mt76_tx_power_nss_delta(n_chains); 1695 1621 *dbm = DIV_ROUND_UP(phy->txpower_cur + delta, 2); 1696 1622 1697 1623 return 0; ··· 1882 1776 { 1883 1777 struct mt76_phy *phy = hw->priv; 1884 1778 struct mt76_dev *dev = phy->dev; 1779 + int i; 1885 1780 1886 1781 mutex_lock(&dev->mutex); 1887 - *tx_ant = phy->antenna_mask; 1888 - *rx_ant = phy->antenna_mask; 1782 + *tx_ant = 0; 1783 + for (i = 0; i < ARRAY_SIZE(dev->phys); i++) 1784 + if (dev->phys[i] && dev->phys[i]->hw == hw) 1785 + *tx_ant |= dev->phys[i]->chainmask; 1786 + *rx_ant = *tx_ant; 1889 1787 mutex_unlock(&dev->mutex); 1890 1788 1891 1789 return 0; ··· 1917 1807 return hwq; 1918 1808 } 1919 1809 EXPORT_SYMBOL_GPL(mt76_init_queue); 1920 - 1921 - u16 mt76_calculate_default_rate(struct mt76_phy *phy, 1922 - struct ieee80211_vif *vif, int rateidx) 1923 - { 1924 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 1925 - struct cfg80211_chan_def *chandef = mvif->ctx ? 1926 - &mvif->ctx->def : 1927 - &phy->chandef; 1928 - int offset = 0; 1929 - 1930 - if (chandef->chan->band != NL80211_BAND_2GHZ) 1931 - offset = 4; 1932 - 1933 - /* pick the lowest rate for hidden nodes */ 1934 - if (rateidx < 0) 1935 - rateidx = 0; 1936 - 1937 - rateidx += offset; 1938 - if (rateidx >= ARRAY_SIZE(mt76_rates)) 1939 - rateidx = offset; 1940 - 1941 - return mt76_rates[rateidx].hw_value; 1942 - } 1943 - EXPORT_SYMBOL_GPL(mt76_calculate_default_rate); 1944 1810 1945 1811 void mt76_ethtool_worker(struct mt76_ethtool_worker_info *wi, 1946 1812 struct mt76_sta_stats *stats, bool eht) ··· 1978 1892 test_bit(MT76_SCANNING, &phy->state)) 1979 1893 return MT_DFS_STATE_DISABLED; 1980 1894 1981 - if (!hw->conf.radar_enabled) { 1895 + if (!phy->radar_enabled) { 1982 1896 if ((hw->conf.flags & IEEE80211_CONF_MONITOR) && 1983 1897 (phy->chandef.chan->flags & IEEE80211_CHAN_RADAR)) 1984 1898 return MT_DFS_STATE_ACTIVE; ··· 1992 1906 return MT_DFS_STATE_ACTIVE; 1993 1907 } 1994 1908 EXPORT_SYMBOL_GPL(mt76_phy_dfs_state); 1909 + 1910 + void mt76_vif_cleanup(struct mt76_dev *dev, struct ieee80211_vif *vif) 1911 + { 1912 + struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv; 1913 + struct mt76_vif_data *mvif = mlink->mvif; 1914 + 1915 + rcu_assign_pointer(mvif->link[0], NULL); 1916 + mt76_abort_scan(dev); 1917 + if (mvif->roc_phy) 1918 + mt76_abort_roc(mvif->roc_phy); 1919 + } 1920 + EXPORT_SYMBOL_GPL(mt76_vif_cleanup);
+144 -8
drivers/net/wireless/mediatek/mt76/mt76.h
··· 50 50 struct mt76_phy; 51 51 struct mt76_wcid; 52 52 struct mt76s_intr; 53 + struct mt76_chanctx; 54 + struct mt76_vif_link; 53 55 54 56 struct mt76_reg_pair { 55 57 u32 reg; ··· 499 497 u16 token_size; 500 498 u8 mcs_rates; 501 499 500 + unsigned int link_data_size; 501 + 502 502 void (*update_survey)(struct mt76_phy *phy); 503 503 int (*set_channel)(struct mt76_phy *phy); 504 504 ··· 532 528 533 529 void (*sta_remove)(struct mt76_dev *dev, struct ieee80211_vif *vif, 534 530 struct ieee80211_sta *sta); 531 + 532 + int (*vif_link_add)(struct mt76_phy *phy, struct ieee80211_vif *vif, 533 + struct ieee80211_bss_conf *link_conf, 534 + struct mt76_vif_link *mlink); 535 + 536 + void (*vif_link_remove)(struct mt76_phy *phy, 537 + struct ieee80211_vif *vif, 538 + struct ieee80211_bss_conf *link_conf, 539 + struct mt76_vif_link *mlink); 535 540 }; 536 541 537 542 struct mt76_channel_state { ··· 649 636 u8 hw_ver; 650 637 wait_queue_head_t wait; 651 638 639 + int pse_mcu_quota_max; 652 640 struct { 653 641 int pse_data_quota; 654 642 int ple_data_quota; ··· 767 753 } rx_stats; 768 754 }; 769 755 770 - struct mt76_vif { 756 + struct mt76_vif_link { 771 757 u8 idx; 772 758 u8 omac_idx; 773 759 u8 band_idx; ··· 777 763 u8 basic_rates_idx; 778 764 u8 mcast_rates_idx; 779 765 u8 beacon_rates_idx; 766 + bool offchannel; 780 767 struct ieee80211_chanctx_conf *ctx; 768 + struct mt76_wcid *wcid; 769 + struct mt76_vif_data *mvif; 770 + struct rcu_head rcu_head; 771 + }; 772 + 773 + struct mt76_vif_data { 774 + struct mt76_vif_link __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS]; 775 + 776 + struct mt76_phy *roc_phy; 777 + u16 valid_links; 778 + u8 deflink_id; 781 779 }; 782 780 783 781 struct mt76_phy { ··· 798 772 void *priv; 799 773 800 774 unsigned long state; 775 + unsigned int num_sta; 801 776 u8 band_idx; 802 777 803 778 spinlock_t tx_lock; ··· 806 779 struct mt76_queue *q_tx[__MT_TXQ_MAX]; 807 780 808 781 struct cfg80211_chan_def chandef; 809 - struct ieee80211_channel *main_chan; 782 + struct cfg80211_chan_def main_chandef; 810 783 bool offchannel; 784 + bool radar_enabled; 785 + 786 + struct delayed_work roc_work; 787 + struct ieee80211_vif *roc_vif; 788 + struct mt76_vif_link *roc_link; 789 + 790 + struct mt76_chanctx *chanctx; 811 791 812 792 struct mt76_channel_state *chan_state; 813 793 enum mt76_dfs_state dfs_state; ··· 859 825 struct mt76_dev { 860 826 struct mt76_phy phy; /* must be first */ 861 827 struct mt76_phy *phys[__MT_MAX_BAND]; 828 + struct mt76_phy *band_phys[NUM_NL80211_BANDS]; 862 829 863 830 struct ieee80211_hw *hw; 864 831 ··· 915 880 spinlock_t status_lock; 916 881 917 882 u32 wcid_mask[DIV_ROUND_UP(MT76_N_WCIDS, 32)]; 918 - u32 wcid_phy_mask[DIV_ROUND_UP(MT76_N_WCIDS, 32)]; 919 883 920 884 u64 vif_mask; 921 885 ··· 942 908 u8 csa_complete; 943 909 944 910 u32 rxfilter; 911 + 912 + struct delayed_work scan_work; 913 + struct { 914 + struct cfg80211_scan_request *req; 915 + struct ieee80211_channel *chan; 916 + struct ieee80211_vif *vif; 917 + struct mt76_vif_link *mlink; 918 + struct mt76_phy *phy; 919 + int chan_idx; 920 + } scan; 945 921 946 922 #ifdef CONFIG_NL80211_TESTMODE 947 923 const struct mt76_testmode_ops *test_ops; ··· 1080 1036 int sta_count; 1081 1037 }; 1082 1038 1039 + struct mt76_chanctx { 1040 + struct mt76_phy *phy; 1041 + }; 1042 + 1083 1043 #define CCK_RATE(_idx, _rate) { \ 1084 1044 .bitrate = _rate, \ 1085 1045 .flags = IEEE80211_RATE_SHORT_PREAMBLE, \ ··· 1204 1156 for (i = 0; i < ARRAY_SIZE((dev)->q_rx); i++) \ 1205 1157 if ((dev)->q_rx[i].ndesc) 1206 1158 1159 + 1160 + #define mt76_dereference(p, dev) \ 1161 + rcu_dereference_protected(p, lockdep_is_held(&(dev)->mutex)) 1162 + 1207 1163 struct mt76_dev *mt76_alloc_device(struct device *pdev, unsigned int size, 1208 1164 const struct ieee80211_ops *ops, 1209 1165 const struct mt76_driver_ops *drv_ops); ··· 1217 1165 void mt76_free_device(struct mt76_dev *dev); 1218 1166 void mt76_unregister_phy(struct mt76_phy *phy); 1219 1167 1168 + struct mt76_phy *mt76_alloc_radio_phy(struct mt76_dev *dev, unsigned int size, 1169 + u8 band_idx); 1220 1170 struct mt76_phy *mt76_alloc_phy(struct mt76_dev *dev, unsigned int size, 1221 1171 const struct ieee80211_ops *ops, 1222 1172 u8 band_idx); ··· 1245 1191 struct mt76_queue * 1246 1192 mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc, 1247 1193 int ring_base, void *wed, u32 flags); 1248 - u16 mt76_calculate_default_rate(struct mt76_phy *phy, 1249 - struct ieee80211_vif *vif, int rateidx); 1250 1194 static inline int mt76_init_tx_queue(struct mt76_phy *phy, int qid, int idx, 1251 1195 int n_desc, int ring_base, void *wed, 1252 1196 u32 flags) ··· 1475 1423 struct ieee80211_sta *sta, 1476 1424 enum ieee80211_sta_state old_state, 1477 1425 enum ieee80211_sta_state new_state); 1478 - void __mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif, 1426 + void __mt76_sta_remove(struct mt76_phy *phy, struct ieee80211_vif *vif, 1479 1427 struct ieee80211_sta *sta); 1480 1428 void mt76_sta_pre_rcu_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1481 1429 struct ieee80211_sta *sta); 1482 1430 1483 - int mt76_get_min_avg_rssi(struct mt76_dev *dev, bool ext_phy); 1431 + int mt76_get_min_avg_rssi(struct mt76_dev *dev, u8 phy_idx); 1484 1432 1485 1433 int mt76_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1486 1434 unsigned int link_id, int *dbm); ··· 1499 1447 int mt76_get_rate(struct mt76_dev *dev, 1500 1448 struct ieee80211_supported_band *sband, 1501 1449 int idx, bool cck); 1450 + int mt76_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1451 + struct ieee80211_scan_request *hw_req); 1452 + void mt76_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif); 1502 1453 void mt76_sw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1503 1454 const u8 *mac); 1504 1455 void mt76_sw_scan_complete(struct ieee80211_hw *hw, 1505 1456 struct ieee80211_vif *vif); 1506 1457 enum mt76_dfs_state mt76_phy_dfs_state(struct mt76_phy *phy); 1458 + int mt76_add_chanctx(struct ieee80211_hw *hw, 1459 + struct ieee80211_chanctx_conf *conf); 1460 + void mt76_remove_chanctx(struct ieee80211_hw *hw, 1461 + struct ieee80211_chanctx_conf *conf); 1462 + void mt76_change_chanctx(struct ieee80211_hw *hw, 1463 + struct ieee80211_chanctx_conf *conf, 1464 + u32 changed); 1465 + int mt76_assign_vif_chanctx(struct ieee80211_hw *hw, 1466 + struct ieee80211_vif *vif, 1467 + struct ieee80211_bss_conf *link_conf, 1468 + struct ieee80211_chanctx_conf *conf); 1469 + void mt76_unassign_vif_chanctx(struct ieee80211_hw *hw, 1470 + struct ieee80211_vif *vif, 1471 + struct ieee80211_bss_conf *link_conf, 1472 + struct ieee80211_chanctx_conf *conf); 1473 + int mt76_switch_vif_chanctx(struct ieee80211_hw *hw, 1474 + struct ieee80211_vif_chanctx_switch *vifs, 1475 + int n_vifs, 1476 + enum ieee80211_chanctx_switch_mode mode); 1477 + int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1478 + struct ieee80211_channel *chan, int duration, 1479 + enum ieee80211_roc_type type); 1480 + int mt76_cancel_remain_on_channel(struct ieee80211_hw *hw, 1481 + struct ieee80211_vif *vif); 1507 1482 int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1508 1483 void *data, int len); 1509 1484 int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb, ··· 1576 1497 void mt76_testmode_tx_pending(struct mt76_phy *phy); 1577 1498 void mt76_queue_tx_complete(struct mt76_dev *dev, struct mt76_queue *q, 1578 1499 struct mt76_queue_entry *e); 1500 + int __mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef, 1501 + bool offchannel); 1579 1502 int mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef, 1580 1503 bool offchannel); 1504 + void mt76_scan_work(struct work_struct *work); 1505 + void mt76_abort_scan(struct mt76_dev *dev); 1506 + void mt76_roc_complete_work(struct work_struct *work); 1507 + void mt76_abort_roc(struct mt76_phy *phy); 1508 + struct mt76_vif_link *mt76_get_vif_phy_link(struct mt76_phy *phy, 1509 + struct ieee80211_vif *vif); 1510 + void mt76_put_vif_phy_link(struct mt76_phy *phy, struct ieee80211_vif *vif, 1511 + struct mt76_vif_link *mlink); 1581 1512 1582 1513 /* usb */ 1583 1514 static inline bool mt76u_urb_error(struct urb *urb) ··· 1823 1734 return txwi; 1824 1735 } 1825 1736 1826 - void mt76_wcid_init(struct mt76_wcid *wcid); 1737 + void mt76_wcid_init(struct mt76_wcid *wcid, u8 band_idx); 1827 1738 void mt76_wcid_cleanup(struct mt76_dev *dev, struct mt76_wcid *wcid); 1739 + void mt76_wcid_add_poll(struct mt76_dev *dev, struct mt76_wcid *wcid); 1740 + 1741 + static inline void 1742 + mt76_vif_init(struct ieee80211_vif *vif, struct mt76_vif_data *mvif) 1743 + { 1744 + struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv; 1745 + 1746 + mlink->mvif = mvif; 1747 + rcu_assign_pointer(mvif->link[0], mlink); 1748 + } 1749 + 1750 + void mt76_vif_cleanup(struct mt76_dev *dev, struct ieee80211_vif *vif); 1751 + 1752 + static inline struct mt76_vif_link * 1753 + mt76_vif_link(struct mt76_dev *dev, struct ieee80211_vif *vif, int link_id) 1754 + { 1755 + struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv; 1756 + struct mt76_vif_data *mvif = mlink->mvif; 1757 + 1758 + return mt76_dereference(mvif->link[link_id], dev); 1759 + } 1760 + 1761 + static inline struct mt76_vif_link * 1762 + mt76_vif_conf_link(struct mt76_dev *dev, struct ieee80211_vif *vif, 1763 + struct ieee80211_bss_conf *link_conf) 1764 + { 1765 + struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv; 1766 + struct mt76_vif_data *mvif = mlink->mvif; 1767 + 1768 + if (link_conf == &vif->bss_conf) 1769 + return mlink; 1770 + 1771 + return mt76_dereference(mvif->link[link_conf->link_id], dev); 1772 + } 1773 + 1774 + static inline struct mt76_phy * 1775 + mt76_vif_link_phy(struct mt76_vif_link *mlink) 1776 + { 1777 + struct mt76_chanctx *ctx; 1778 + 1779 + if (!mlink->ctx) 1780 + return NULL; 1781 + 1782 + ctx = (struct mt76_chanctx *)mlink->ctx->drv_priv; 1783 + 1784 + return ctx->phy; 1785 + } 1828 1786 1829 1787 #endif
+2 -7
drivers/net/wireless/mediatek/mt76/mt7603/mac.c
··· 1277 1277 1278 1278 msta = container_of(wcid, struct mt7603_sta, wcid); 1279 1279 sta = wcid_to_sta(wcid); 1280 - 1281 - if (list_empty(&msta->wcid.poll_list)) { 1282 - spin_lock_bh(&dev->mt76.sta_poll_lock); 1283 - list_add_tail(&msta->wcid.poll_list, &dev->mt76.sta_poll_list); 1284 - spin_unlock_bh(&dev->mt76.sta_poll_lock); 1285 - } 1280 + mt76_wcid_add_poll(&dev->mt76, &msta->wcid); 1286 1281 1287 1282 if (mt7603_mac_add_txs_skb(dev, msta, pid, txs_data)) 1288 1283 goto out; ··· 1788 1793 1789 1794 mt7603_cca_stats_reset(dev); 1790 1795 1791 - min_signal = mt76_get_min_avg_rssi(&dev->mt76, false); 1796 + min_signal = mt76_get_min_avg_rssi(&dev->mt76, 0); 1792 1797 if (!min_signal) { 1793 1798 dev->sensitivity = 0; 1794 1799 dev->last_cca_adj = jiffies;
+1 -3
drivers/net/wireless/mediatek/mt76/mt7603/main.c
··· 66 66 67 67 idx = MT7603_WTBL_RESERVED - 1 - mvif->idx; 68 68 dev->mt76.vif_mask |= BIT_ULL(mvif->idx); 69 - INIT_LIST_HEAD(&mvif->sta.wcid.poll_list); 70 69 mvif->sta.wcid.idx = idx; 71 - mvif->sta.wcid.hw_key_idx = -1; 72 70 mvif->sta.vif = mvif; 73 - mt76_wcid_init(&mvif->sta.wcid); 71 + mt76_wcid_init(&mvif->sta.wcid, 0); 74 72 75 73 eth_broadcast_addr(bc_addr); 76 74 mt7603_wtbl_init(dev, idx, mvif->idx, bc_addr);
+3 -11
drivers/net/wireless/mediatek/mt76/mt7615/mac.c
··· 387 387 struct mt7615_sta *msta; 388 388 389 389 msta = container_of(status->wcid, struct mt7615_sta, wcid); 390 - spin_lock_bh(&dev->mt76.sta_poll_lock); 391 - if (list_empty(&msta->wcid.poll_list)) 392 - list_add_tail(&msta->wcid.poll_list, 393 - &dev->mt76.sta_poll_list); 394 - spin_unlock_bh(&dev->mt76.sta_poll_lock); 390 + mt76_wcid_add_poll(&dev->mt76, &msta->wcid); 395 391 } 396 392 397 393 if (mt76_is_mmio(&dev->mt76) && (rxd0 & csum_mask) == csum_mask && ··· 730 734 u16 seqno = 0; 731 735 732 736 if (vif) { 733 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 737 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 734 738 735 739 omac_idx = mvif->omac_idx; 736 740 wmm_idx = mvif->wmm_idx; ··· 1510 1514 1511 1515 msta = container_of(wcid, struct mt7615_sta, wcid); 1512 1516 sta = wcid_to_sta(wcid); 1513 - 1514 - spin_lock_bh(&dev->mt76.sta_poll_lock); 1515 - if (list_empty(&msta->wcid.poll_list)) 1516 - list_add_tail(&msta->wcid.poll_list, &dev->mt76.sta_poll_list); 1517 - spin_unlock_bh(&dev->mt76.sta_poll_lock); 1517 + mt76_wcid_add_poll(&dev->mt76, &msta->wcid); 1518 1518 1519 1519 if (mt7615_mac_add_txs_skb(dev, msta, pid, txs_data)) 1520 1520 goto out;
+5 -6
drivers/net/wireless/mediatek/mt76/mt7615/main.c
··· 209 209 210 210 mvif->mt76.band_idx = ext_phy; 211 211 mvif->mt76.wmm_idx = vif->type != NL80211_IFTYPE_AP; 212 + mvif->mt76.wcid = &mvif->sta.wcid; 212 213 if (ext_phy) 213 214 mvif->mt76.wmm_idx += 2; 214 215 ··· 225 224 226 225 INIT_LIST_HEAD(&mvif->sta.wcid.poll_list); 227 226 mvif->sta.wcid.idx = idx; 228 - mvif->sta.wcid.phy_idx = mvif->mt76.band_idx; 229 - mvif->sta.wcid.hw_key_idx = -1; 230 - mt76_wcid_init(&mvif->sta.wcid); 227 + mt76_wcid_init(&mvif->sta.wcid, mvif->mt76.band_idx); 231 228 232 229 mt7615_mac_wtbl_update(dev, idx, 233 230 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); ··· 462 463 unsigned int link_id, u16 queue, 463 464 const struct ieee80211_tx_queue_params *params) 464 465 { 465 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 466 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 466 467 struct mt7615_dev *dev = mt7615_hw_dev(hw); 467 468 int err; 468 469 ··· 1248 1249 phy->mt76); 1249 1250 1250 1251 if (!mt7615_dev_running(dev)) 1251 - err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, true); 1252 + err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, true, true); 1252 1253 1253 1254 mt7615_mutex_release(dev); 1254 1255 ··· 1270 1271 if (!running) { 1271 1272 int err; 1272 1273 1273 - err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, false); 1274 + err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, false, true); 1274 1275 if (err < 0) { 1275 1276 mt7615_mutex_release(dev); 1276 1277 return err;
+4 -4
drivers/net/wireless/mediatek/mt76/mt7615/mcu.c
··· 865 865 mvif->sta_added = true; 866 866 } 867 867 conn_state = enable ? CONN_STATE_PORT_SECURE : CONN_STATE_DISCONNECT; 868 - mt76_connac_mcu_sta_basic_tlv(&dev->mt76, sskb, vif, link_sta, 869 - conn_state, new_entry); 868 + mt76_connac_mcu_sta_basic_tlv(&dev->mt76, sskb, &vif->bss_conf, 869 + link_sta, conn_state, new_entry); 870 870 if (enable && sta) 871 871 mt76_connac_mcu_sta_tlv(phy->mt76, sskb, sta, vif, 0, 872 872 MT76_STA_INFO_STATE_ASSOC); ··· 1113 1113 { 1114 1114 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv; 1115 1115 1116 - return mt76_connac_mcu_uni_add_dev(phy->mt76, &vif->bss_conf, 1116 + return mt76_connac_mcu_uni_add_dev(phy->mt76, &vif->bss_conf, &mvif->mt76, 1117 1117 &mvif->sta.wcid, enable); 1118 1118 } 1119 1119 ··· 1700 1700 }; 1701 1701 int ret; 1702 1702 1703 - dev->mt76.mcu_ops = &mt7615_mcu_ops, 1703 + dev->mt76.mcu_ops = &mt7615_mcu_ops; 1704 1704 1705 1705 ret = mt7615_mcu_drv_pmctrl(dev); 1706 1706 if (ret)
+1 -1
drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h
··· 139 139 }; 140 140 141 141 struct mt7615_vif { 142 - struct mt76_vif mt76; /* must be first */ 142 + struct mt76_vif_link mt76; /* must be first */ 143 143 struct mt7615_sta sta; 144 144 bool sta_added; 145 145 };
+3 -3
drivers/net/wireless/mediatek/mt76/mt7615/pci.c
··· 83 83 hif_suspend = !test_bit(MT76_STATE_SUSPEND, &dev->mphy.state) && 84 84 mt7615_firmware_offload(dev); 85 85 if (hif_suspend) { 86 - err = mt76_connac_mcu_set_hif_suspend(mdev, true); 86 + err = mt76_connac_mcu_set_hif_suspend(mdev, true, true); 87 87 if (err) 88 88 return err; 89 89 } ··· 131 131 } 132 132 napi_enable(&mdev->tx_napi); 133 133 if (hif_suspend) 134 - mt76_connac_mcu_set_hif_suspend(mdev, false); 134 + mt76_connac_mcu_set_hif_suspend(mdev, false, true); 135 135 136 136 return err; 137 137 } ··· 175 175 176 176 if (!test_bit(MT76_STATE_SUSPEND, &dev->mphy.state) && 177 177 mt7615_firmware_offload(dev)) 178 - err = mt76_connac_mcu_set_hif_suspend(mdev, false); 178 + err = mt76_connac_mcu_set_hif_suspend(mdev, false, true); 179 179 180 180 return err; 181 181 }
+1 -1
drivers/net/wireless/mediatek/mt76/mt7615/pci_mac.c
··· 48 48 txp->flags |= cpu_to_le16(MT_CT_INFO_MGMT_FRAME); 49 49 50 50 if (vif) { 51 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 51 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 52 52 53 53 txp->bss_idx = mvif->idx; 54 54 }
+2 -2
drivers/net/wireless/mediatek/mt76/mt7615/sdio.c
··· 191 191 mt7615_firmware_offload(mdev)) { 192 192 int err; 193 193 194 - err = mt76_connac_mcu_set_hif_suspend(&mdev->mt76, true); 194 + err = mt76_connac_mcu_set_hif_suspend(&mdev->mt76, true, true); 195 195 if (err < 0) 196 196 return err; 197 197 } ··· 230 230 231 231 if (!test_bit(MT76_STATE_SUSPEND, &mdev->mphy.state) && 232 232 mt7615_firmware_offload(mdev)) 233 - err = mt76_connac_mcu_set_hif_suspend(&mdev->mt76, false); 233 + err = mt76_connac_mcu_set_hif_suspend(&mdev->mt76, false, true); 234 234 235 235 return err; 236 236 }
+1 -1
drivers/net/wireless/mediatek/mt76/mt7615/sdio_mcu.c
··· 147 147 if (ret) 148 148 return ret; 149 149 150 - dev->mt76.mcu_ops = &mt7663s_mcu_ops, 150 + dev->mt76.mcu_ops = &mt7663s_mcu_ops; 151 151 152 152 ret = mt76_get_field(dev, MT_CONN_ON_MISC, MT_TOP_MISC2_FW_N9_RDY); 153 153 if (ret) {
+2 -2
drivers/net/wireless/mediatek/mt76/mt7615/usb.c
··· 225 225 mt7615_firmware_offload(dev)) { 226 226 int err; 227 227 228 - err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, true); 228 + err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, true, true); 229 229 if (err < 0) 230 230 return err; 231 231 } ··· 253 253 254 254 if (!test_bit(MT76_STATE_SUSPEND, &dev->mphy.state) && 255 255 mt7615_firmware_offload(dev)) 256 - err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, false); 256 + err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, false, true); 257 257 258 258 return err; 259 259 }
+1 -1
drivers/net/wireless/mediatek/mt76/mt7615/usb_mcu.c
··· 72 72 }; 73 73 int ret; 74 74 75 - dev->mt76.mcu_ops = &mt7663u_mcu_ops, 75 + dev->mt76.mcu_ops = &mt7663u_mcu_ops; 76 76 77 77 mt76_set(dev, MT_UDMA_TX_QSEL, MT_FW_DL_EN); 78 78 if (test_and_clear_bit(MT76_STATE_POWER_OFF, &dev->mphy.state)) {
+2 -2
drivers/net/wireless/mediatek/mt76/mt76_connac.h
··· 405 405 mutex_unlock(&dev->mutex); 406 406 } 407 407 408 - void mt76_connac_gen_ppe_thresh(u8 *he_ppet, int nss); 408 + void mt76_connac_gen_ppe_thresh(u8 *he_ppet, int nss, enum nl80211_band band); 409 409 int mt76_connac_init_tx_queues(struct mt76_phy *phy, int idx, int n_desc, 410 410 int ring_base, void *wed, u32 flags); 411 411 ··· 427 427 struct ieee80211_key_conf *key, int pid, 428 428 enum mt76_txq_id qid, u32 changed); 429 429 u16 mt76_connac2_mac_tx_rate_val(struct mt76_phy *mphy, 430 - struct ieee80211_vif *vif, 430 + struct ieee80211_bss_conf *conf, 431 431 bool beacon, bool mcast); 432 432 bool mt76_connac2_mac_fill_txs(struct mt76_dev *dev, struct mt76_wcid *wcid, 433 433 __le32 *txs_data);
+3 -2
drivers/net/wireless/mediatek/mt76/mt76_connac3_mac.c
··· 231 231 EHT_PREP(DATA0_PE_DISAMBIGUITY_OM, PE_DISAMBIG, rxv[5]) | 232 232 EHT_PREP(DATA0_LDPC_EXTRA_SYM_OM, LDPC_EXT_SYM, rxv[4]); 233 233 234 - eht->data[7] |= le32_encode_bits(status->nss, IEEE80211_RADIOTAP_EHT_DATA7_NSS_S); 234 + /* iwlwifi and wireshark expect radiotap to report zero-based NSS, so subtract 1. */ 235 + eht->data[7] |= le32_encode_bits(status->nss - 1, IEEE80211_RADIOTAP_EHT_DATA7_NSS_S); 235 236 236 237 eht->user_info[0] |= 237 238 EHT_BITS(USER_INFO_MCS_KNOWN) | ··· 241 240 EHT_BITS(USER_INFO_BEAMFORMING_KNOWN_O) | 242 241 EHT_BITS(USER_INFO_DATA_FOR_USER) | 243 242 le32_encode_bits(status->rate_idx, IEEE80211_RADIOTAP_EHT_USER_INFO_MCS) | 244 - le32_encode_bits(status->nss, IEEE80211_RADIOTAP_EHT_USER_INFO_NSS_O); 243 + le32_encode_bits(status->nss - 1, IEEE80211_RADIOTAP_EHT_USER_INFO_NSS_O); 245 244 246 245 if (le32_to_cpu(rxv[0]) & MT_PRXV_TXBF) 247 246 eht->user_info[0] |= EHT_BITS(USER_INFO_BEAMFORMING_O);
+28 -17
drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c
··· 9 9 #define HE_PREP(f, m, v) le16_encode_bits(le32_get_bits(v, MT_CRXV_HE_##m),\ 10 10 IEEE80211_RADIOTAP_HE_##f) 11 11 12 - void mt76_connac_gen_ppe_thresh(u8 *he_ppet, int nss) 12 + void mt76_connac_gen_ppe_thresh(u8 *he_ppet, int nss, enum nl80211_band band) 13 13 { 14 14 static const u8 ppet16_ppet8_ru3_ru0[] = { 0x1c, 0xc7, 0x71 }; 15 - u8 i, ppet_bits, ppet_size, ru_bit_mask = 0x7; /* HE80 */ 15 + u8 i, ppet_bits, ppet_size, ru_bit_mask = 0xf; 16 + 17 + if (band == NL80211_BAND_2GHZ) 18 + ru_bit_mask = 0x3; 16 19 17 20 he_ppet[0] = FIELD_PREP(IEEE80211_PPE_THRES_NSS_MASK, nss - 1) | 18 21 FIELD_PREP(IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK, ··· 294 291 }) 295 292 296 293 u16 mt76_connac2_mac_tx_rate_val(struct mt76_phy *mphy, 297 - struct ieee80211_vif *vif, 294 + struct ieee80211_bss_conf *conf, 298 295 bool beacon, bool mcast) 299 296 { 300 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 297 + struct mt76_vif_link *mvif = mt76_vif_conf_link(mphy->dev, conf->vif, conf); 301 298 struct cfg80211_chan_def *chandef = mvif->ctx ? 302 299 &mvif->ctx->def : &mphy->chandef; 303 300 u8 nss = 0, mode = 0, band = chandef->chan->band; 304 301 int rateidx = 0, mcast_rate; 302 + int offset = 0; 305 303 306 - if (!vif) 304 + if (!conf) 307 305 goto legacy; 308 306 309 307 if (is_mt7921(mphy->dev)) { 310 - rateidx = ffs(vif->bss_conf.basic_rates) - 1; 308 + rateidx = ffs(conf->basic_rates) - 1; 311 309 goto legacy; 312 310 } 313 311 314 312 if (beacon) { 315 313 struct cfg80211_bitrate_mask *mask; 316 314 317 - mask = &vif->bss_conf.beacon_tx_rate; 315 + mask = &conf->beacon_tx_rate; 318 316 319 317 __bitrate_mask_check(he_mcs, HE_SU); 320 318 __bitrate_mask_check(vht_mcs, VHT); ··· 327 323 } 328 324 } 329 325 330 - mcast_rate = vif->bss_conf.mcast_rate[band]; 326 + mcast_rate = conf->mcast_rate[band]; 331 327 if (mcast && mcast_rate > 0) 332 328 rateidx = mcast_rate - 1; 333 329 else 334 - rateidx = ffs(vif->bss_conf.basic_rates) - 1; 330 + rateidx = ffs(conf->basic_rates) - 1; 335 331 336 332 legacy: 337 - rateidx = mt76_calculate_default_rate(mphy, vif, rateidx); 333 + if (band != NL80211_BAND_2GHZ) 334 + offset = 4; 335 + 336 + /* pick the lowest rate for hidden nodes */ 337 + if (rateidx < 0) 338 + rateidx = 0; 339 + 340 + rateidx += offset; 341 + if (rateidx >= ARRAY_SIZE(mt76_rates)) 342 + rateidx = offset; 343 + 344 + rateidx = mt76_rates[rateidx].hw_value; 338 345 mode = rateidx >> 8; 339 346 rateidx &= GENMASK(7, 0); 340 347 out: ··· 508 493 bool amsdu_en = wcid->amsdu; 509 494 510 495 if (vif) { 511 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 496 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 512 497 513 498 omac_idx = mvif->omac_idx; 514 499 wmm_idx = mvif->wmm_idx; ··· 584 569 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 585 570 bool multicast = ieee80211_is_data(hdr->frame_control) && 586 571 is_multicast_ether_addr(hdr->addr1); 587 - u16 rate = mt76_connac2_mac_tx_rate_val(mphy, vif, beacon, 572 + u16 rate = mt76_connac2_mac_tx_rate_val(mphy, &vif->bss_conf, beacon, 588 573 multicast); 589 574 u32 val = MT_TXD6_FIXED_BW; 590 575 ··· 1177 1162 if (wcid && wcid->sta) { 1178 1163 sta = container_of((void *)wcid, struct ieee80211_sta, 1179 1164 drv_priv); 1180 - spin_lock_bh(&dev->sta_poll_lock); 1181 - if (list_empty(&wcid->poll_list)) 1182 - list_add_tail(&wcid->poll_list, 1183 - &dev->sta_poll_list); 1184 - spin_unlock_bh(&dev->sta_poll_lock); 1165 + mt76_wcid_add_poll(dev, wcid); 1185 1166 } 1186 1167 } 1187 1168
+43 -36
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
··· 189 189 190 190 int mt76_connac_mcu_set_vif_ps(struct mt76_dev *dev, struct ieee80211_vif *vif) 191 191 { 192 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 192 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 193 193 struct { 194 194 u8 bss_idx; 195 195 u8 ps_state; /* 0: device awake ··· 232 232 void mt76_connac_mcu_beacon_loss_iter(void *priv, u8 *mac, 233 233 struct ieee80211_vif *vif) 234 234 { 235 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 235 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 236 236 struct mt76_connac_beacon_loss_event *event = priv; 237 237 238 238 if (mvif->idx != event->bss_idx) ··· 273 273 EXPORT_SYMBOL_GPL(mt76_connac_mcu_add_nested_tlv); 274 274 275 275 struct sk_buff * 276 - __mt76_connac_mcu_alloc_sta_req(struct mt76_dev *dev, struct mt76_vif *mvif, 276 + __mt76_connac_mcu_alloc_sta_req(struct mt76_dev *dev, struct mt76_vif_link *mvif, 277 277 struct mt76_wcid *wcid, int len) 278 278 { 279 279 struct sta_req_hdr hdr = { ··· 329 329 void mt76_connac_mcu_bss_omac_tlv(struct sk_buff *skb, 330 330 struct ieee80211_vif *vif) 331 331 { 332 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 332 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 333 333 u8 omac_idx = mvif->omac_idx; 334 334 struct bss_info_omac *omac; 335 335 struct tlv *tlv; ··· 369 369 EXPORT_SYMBOL_GPL(mt76_connac_mcu_bss_omac_tlv); 370 370 371 371 void mt76_connac_mcu_sta_basic_tlv(struct mt76_dev *dev, struct sk_buff *skb, 372 - struct ieee80211_vif *vif, 372 + struct ieee80211_bss_conf *link_conf, 373 373 struct ieee80211_link_sta *link_sta, 374 374 int conn_state, bool newly) 375 375 { 376 + struct ieee80211_vif *vif = link_conf->vif; 376 377 struct sta_rec_basic *basic; 377 378 struct tlv *tlv; 378 379 int conn_type; ··· 391 390 basic->conn_type = cpu_to_le32(CONNECTION_INFRA_BC); 392 391 393 392 if (vif->type == NL80211_IFTYPE_STATION && 394 - !is_zero_ether_addr(vif->bss_conf.bssid)) { 395 - memcpy(basic->peer_addr, vif->bss_conf.bssid, ETH_ALEN); 393 + !is_zero_ether_addr(link_conf->bssid)) { 394 + memcpy(basic->peer_addr, link_conf->bssid, ETH_ALEN); 396 395 basic->aid = cpu_to_le16(vif->cfg.aid); 397 396 } else { 398 397 eth_broadcast_addr(basic->peer_addr); ··· 498 497 struct ieee80211_vif *vif, 499 498 struct mt76_wcid *wcid, int cmd) 500 499 { 501 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 500 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 502 501 struct wtbl_req_hdr *wtbl_hdr; 503 502 struct tlv *sta_wtbl; 504 503 struct sk_buff *skb; ··· 546 545 struct ieee80211_sta *sta, 547 546 void *sta_wtbl, void *wtbl_tlv) 548 547 { 549 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 548 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 550 549 struct wtbl_generic *generic; 551 550 struct wtbl_rx *rx; 552 551 struct wtbl_spe *spe; ··· 850 849 struct ieee80211_vif *vif, 851 850 u8 rcpi, u8 sta_state) 852 851 { 853 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 852 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 854 853 struct cfg80211_chan_def *chandef = mvif->ctx ? 855 854 &mvif->ctx->def : &mphy->chandef; 856 855 enum nl80211_band band = chandef->chan->band; ··· 1042 1041 int mt76_connac_mcu_sta_cmd(struct mt76_phy *phy, 1043 1042 struct mt76_sta_cmd_info *info) 1044 1043 { 1045 - struct mt76_vif *mvif = (struct mt76_vif *)info->vif->drv_priv; 1044 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)info->vif->drv_priv; 1046 1045 struct ieee80211_link_sta *link_sta; 1047 1046 struct mt76_dev *dev = phy->dev; 1048 1047 struct wtbl_req_hdr *wtbl_hdr; 1049 1048 struct tlv *sta_wtbl; 1050 1049 struct sk_buff *skb; 1051 1050 int conn_state; 1051 + 1052 + if (!info->link_conf) 1053 + info->link_conf = &info->vif->bss_conf; 1052 1054 1053 1055 skb = mt76_connac_mcu_alloc_sta_req(dev, mvif, info->wcid); 1054 1056 if (IS_ERR(skb)) ··· 1061 1057 CONN_STATE_DISCONNECT; 1062 1058 link_sta = info->sta ? &info->sta->deflink : NULL; 1063 1059 if (info->sta || !info->offload_fw) 1064 - mt76_connac_mcu_sta_basic_tlv(dev, skb, info->vif, 1060 + mt76_connac_mcu_sta_basic_tlv(dev, skb, info->link_conf, 1065 1061 link_sta, conn_state, 1066 1062 info->newly); 1067 1063 if (info->sta && info->enable) ··· 1141 1137 1142 1138 int mt76_connac_mcu_uni_add_dev(struct mt76_phy *phy, 1143 1139 struct ieee80211_bss_conf *bss_conf, 1140 + struct mt76_vif_link *mvif, 1144 1141 struct mt76_wcid *wcid, 1145 1142 bool enable) 1146 1143 { 1147 - struct mt76_vif *mvif = (struct mt76_vif *)bss_conf->vif->drv_priv; 1148 1144 struct mt76_dev *dev = phy->dev; 1149 1145 struct { 1150 1146 struct { ··· 1205 1201 break; 1206 1202 case NL80211_IFTYPE_STATION: 1207 1203 basic_req.basic.conn_type = cpu_to_le32(CONNECTION_INFRA_STA); 1204 + break; 1205 + case NL80211_IFTYPE_P2P_DEVICE: 1206 + basic_req.basic.conn_type = cpu_to_le32(CONNECTION_P2P_GO); 1208 1207 break; 1209 1208 case NL80211_IFTYPE_ADHOC: 1210 1209 basic_req.basic.conn_type = cpu_to_le32(CONNECTION_IBSS_ADHOC); ··· 1270 1263 } 1271 1264 EXPORT_SYMBOL_GPL(mt76_connac_mcu_sta_wed_update); 1272 1265 1273 - int mt76_connac_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif *mvif, 1266 + int mt76_connac_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif_link *mvif, 1274 1267 struct ieee80211_ampdu_params *params, 1275 1268 int cmd, bool enable, bool tx) 1276 1269 { ··· 1371 1364 } 1372 1365 EXPORT_SYMBOL_GPL(mt76_connac_get_phy_mode); 1373 1366 1374 - u8 mt76_connac_get_phy_mode_ext(struct mt76_phy *phy, struct ieee80211_vif *vif, 1367 + u8 mt76_connac_get_phy_mode_ext(struct mt76_phy *phy, struct ieee80211_bss_conf *conf, 1375 1368 enum nl80211_band band) 1376 1369 { 1377 1370 const struct ieee80211_sta_eht_cap *eht_cap; ··· 1382 1375 mode |= PHY_MODE_AX_6G; 1383 1376 1384 1377 sband = phy->hw->wiphy->bands[band]; 1385 - eht_cap = ieee80211_get_eht_iftype_cap(sband, vif->type); 1378 + eht_cap = ieee80211_get_eht_iftype_cap(sband, conf->vif->type); 1386 1379 1387 - if (!eht_cap || !eht_cap->has_eht || !vif->bss_conf.eht_support) 1380 + if (!eht_cap || !eht_cap->has_eht || !conf->eht_support) 1388 1381 return mode; 1389 1382 1390 1383 switch (band) { ··· 1408 1401 const struct ieee80211_sta_he_cap * 1409 1402 mt76_connac_get_he_phy_cap(struct mt76_phy *phy, struct ieee80211_vif *vif) 1410 1403 { 1411 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 1404 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 1412 1405 struct cfg80211_chan_def *chandef = mvif->ctx ? 1413 1406 &mvif->ctx->def : &phy->chandef; 1414 1407 enum nl80211_band band = chandef->chan->band; ··· 1457 1450 he->max_nss_mcs[CMD_HE_MCS_BW8080] = cap->he_mcs_nss_supp.tx_mcs_80p80; 1458 1451 } 1459 1452 1460 - int mt76_connac_mcu_uni_set_chctx(struct mt76_phy *phy, struct mt76_vif *mvif, 1453 + int mt76_connac_mcu_uni_set_chctx(struct mt76_phy *phy, struct mt76_vif_link *mvif, 1461 1454 struct ieee80211_chanctx_conf *ctx) 1462 1455 { 1463 1456 struct cfg80211_chan_def *chandef = ctx ? &ctx->def : &phy->chandef; ··· 1545 1538 bool enable, 1546 1539 struct ieee80211_chanctx_conf *ctx) 1547 1540 { 1548 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 1541 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 1549 1542 struct cfg80211_chan_def *chandef = ctx ? &ctx->def : &phy->chandef; 1550 1543 enum nl80211_band band = chandef->chan->band; 1551 1544 struct mt76_dev *mdev = phy->dev; ··· 1671 1664 int mt76_connac_mcu_hw_scan(struct mt76_phy *phy, struct ieee80211_vif *vif, 1672 1665 struct ieee80211_scan_request *scan_req) 1673 1666 { 1674 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 1667 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 1675 1668 struct cfg80211_scan_request *sreq = &scan_req->req; 1676 1669 int n_ssids = 0, err, i, duration; 1677 1670 int ext_channels_num = max_t(int, sreq->n_channels - 32, 0); ··· 1777 1770 int mt76_connac_mcu_cancel_hw_scan(struct mt76_phy *phy, 1778 1771 struct ieee80211_vif *vif) 1779 1772 { 1780 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 1773 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 1781 1774 struct { 1782 1775 u8 seq_num; 1783 1776 u8 is_ext_channel; ··· 1803 1796 struct ieee80211_vif *vif, 1804 1797 struct cfg80211_sched_scan_request *sreq) 1805 1798 { 1806 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 1799 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 1807 1800 struct ieee80211_channel **scan_list = sreq->channels; 1808 1801 struct mt76_connac_mcu_scan_channel *chan; 1809 1802 struct mt76_connac_sched_scan_req *req; ··· 2215 2208 EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_rate_txpower); 2216 2209 2217 2210 int mt76_connac_mcu_update_arp_filter(struct mt76_dev *dev, 2218 - struct mt76_vif *vif, 2211 + struct mt76_vif_link *vif, 2219 2212 struct ieee80211_bss_conf *info) 2220 2213 { 2221 2214 struct ieee80211_vif *mvif = container_of(info, struct ieee80211_vif, ··· 2258 2251 int mt76_connac_mcu_set_p2p_oppps(struct ieee80211_hw *hw, 2259 2252 struct ieee80211_vif *vif) 2260 2253 { 2261 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 2254 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 2262 2255 int ct_window = vif->bss_conf.p2p_noa_attr.oppps_ctwindow; 2263 2256 struct mt76_phy *phy = hw->priv; 2264 2257 struct { ··· 2325 2318 struct ieee80211_vif *vif, 2326 2319 struct cfg80211_gtk_rekey_data *key) 2327 2320 { 2328 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 2321 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 2329 2322 struct mt76_connac_gtk_rekey_tlv *gtk_tlv; 2330 2323 struct mt76_phy *phy = hw->priv; 2331 2324 struct sk_buff *skb; ··· 2366 2359 mt76_connac_mcu_set_arp_filter(struct mt76_dev *dev, struct ieee80211_vif *vif, 2367 2360 bool suspend) 2368 2361 { 2369 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 2362 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 2370 2363 struct { 2371 2364 struct { 2372 2365 u8 bss_idx; ··· 2392 2385 mt76_connac_mcu_set_gtk_rekey(struct mt76_dev *dev, struct ieee80211_vif *vif, 2393 2386 bool suspend) 2394 2387 { 2395 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 2388 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 2396 2389 struct { 2397 2390 struct { 2398 2391 u8 bss_idx; ··· 2421 2414 bool enable, u8 mdtim, 2422 2415 bool wow_suspend) 2423 2416 { 2424 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 2417 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 2425 2418 struct { 2426 2419 struct { 2427 2420 u8 bss_idx; ··· 2452 2445 u8 index, bool enable, 2453 2446 struct cfg80211_pkt_pattern *pattern) 2454 2447 { 2455 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 2448 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 2456 2449 struct mt76_connac_wow_pattern_tlv *ptlv; 2457 2450 struct sk_buff *skb; 2458 2451 struct req_hdr { ··· 2484 2477 mt76_connac_mcu_set_wow_ctrl(struct mt76_phy *phy, struct ieee80211_vif *vif, 2485 2478 bool suspend, struct cfg80211_wowlan *wowlan) 2486 2479 { 2487 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 2480 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 2488 2481 struct mt76_dev *dev = phy->dev; 2489 2482 struct { 2490 2483 struct { ··· 2534 2527 } 2535 2528 EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_wow_ctrl); 2536 2529 2537 - int mt76_connac_mcu_set_hif_suspend(struct mt76_dev *dev, bool suspend) 2530 + int mt76_connac_mcu_set_hif_suspend(struct mt76_dev *dev, bool suspend, bool wait_resp) 2538 2531 { 2539 2532 struct { 2540 2533 struct { ··· 2566 2559 req.hdr.hif_type = 0; 2567 2560 2568 2561 return mt76_mcu_send_msg(dev, MCU_UNI_CMD(HIF_CTRL), &req, 2569 - sizeof(req), true); 2562 + sizeof(req), wait_resp); 2570 2563 } 2571 2564 EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_hif_suspend); 2572 2565 ··· 2693 2686 struct ieee80211_key_conf *key, int mcu_cmd, 2694 2687 struct mt76_wcid *wcid, enum set_key_cmd cmd) 2695 2688 { 2696 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 2689 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 2697 2690 struct sk_buff *skb; 2698 2691 int ret; 2699 2692 ··· 2715 2708 2716 2709 /* SIFS 20us + 512 byte beacon transmitted by 1Mbps (3906us) */ 2717 2710 #define BCN_TX_ESTIMATE_TIME (4096 + 20) 2718 - void mt76_connac_mcu_bss_ext_tlv(struct sk_buff *skb, struct mt76_vif *mvif) 2711 + void mt76_connac_mcu_bss_ext_tlv(struct sk_buff *skb, struct mt76_vif_link *mvif) 2719 2712 { 2720 2713 struct bss_info_ext_bss *ext; 2721 2714 int ext_bss_idx, tsf_offset; ··· 2739 2732 struct mt76_phy *phy, u16 wlan_idx, 2740 2733 bool enable) 2741 2734 { 2742 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 2735 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 2743 2736 u32 type = vif->p2p ? NETWORK_P2P : NETWORK_INFRA; 2744 2737 struct bss_info_basic *bss; 2745 2738 struct tlv *tlv;
+14 -9
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
··· 1043 1043 MCU_EXT_EVENT_CSA_NOTIFY = 0x4f, 1044 1044 MCU_EXT_EVENT_WA_TX_STAT = 0x74, 1045 1045 MCU_EXT_EVENT_BCC_NOTIFY = 0x75, 1046 + MCU_EXT_EVENT_WF_RF_PIN_CTRL = 0x9a, 1046 1047 MCU_EXT_EVENT_MURU_CTRL = 0x9f, 1047 1048 }; 1048 1049 1049 1050 /* unified event table */ 1050 1051 enum { 1051 1052 MCU_UNI_EVENT_RESULT = 0x01, 1053 + MCU_UNI_EVENT_HIF_CTRL = 0x03, 1052 1054 MCU_UNI_EVENT_FW_LOG_2_HOST = 0x04, 1053 1055 MCU_UNI_EVENT_ACCESS_REG = 0x6, 1054 1056 MCU_UNI_EVENT_IE_COUNTDOWN = 0x09, ··· 1253 1251 MCU_EXT_CMD_GROUP_PRE_CAL_INFO = 0xab, 1254 1252 MCU_EXT_CMD_DPD_PRE_CAL_INFO = 0xac, 1255 1253 MCU_EXT_CMD_PHY_STAT_INFO = 0xad, 1254 + MCU_EXT_CMD_WF_RF_PIN_CTRL = 0xbd, 1256 1255 }; 1257 1256 1258 1257 enum { ··· 1759 1756 struct mt76_wcid *wcid; 1760 1757 1761 1758 struct ieee80211_vif *vif; 1759 + struct ieee80211_bss_conf *link_conf; 1762 1760 1763 1761 bool offload_fw; 1764 1762 bool enable; ··· 1880 1876 } 1881 1877 1882 1878 struct sk_buff * 1883 - __mt76_connac_mcu_alloc_sta_req(struct mt76_dev *dev, struct mt76_vif *mvif, 1879 + __mt76_connac_mcu_alloc_sta_req(struct mt76_dev *dev, struct mt76_vif_link *mvif, 1884 1880 struct mt76_wcid *wcid, int len); 1885 1881 static inline struct sk_buff * 1886 - mt76_connac_mcu_alloc_sta_req(struct mt76_dev *dev, struct mt76_vif *mvif, 1882 + mt76_connac_mcu_alloc_sta_req(struct mt76_dev *dev, struct mt76_vif_link *mvif, 1887 1883 struct mt76_wcid *wcid) 1888 1884 { 1889 1885 return __mt76_connac_mcu_alloc_sta_req(dev, mvif, wcid, ··· 1905 1901 int mt76_connac_mcu_set_channel_domain(struct mt76_phy *phy); 1906 1902 int mt76_connac_mcu_set_vif_ps(struct mt76_dev *dev, struct ieee80211_vif *vif); 1907 1903 void mt76_connac_mcu_sta_basic_tlv(struct mt76_dev *dev, struct sk_buff *skb, 1908 - struct ieee80211_vif *vif, 1904 + struct ieee80211_bss_conf *link_conf, 1909 1905 struct ieee80211_link_sta *link_sta, 1910 1906 int state, bool newly); 1911 1907 void mt76_connac_mcu_wtbl_generic_tlv(struct mt76_dev *dev, struct sk_buff *skb, ··· 1942 1938 bool enable, bool tx); 1943 1939 int mt76_connac_mcu_uni_add_dev(struct mt76_phy *phy, 1944 1940 struct ieee80211_bss_conf *bss_conf, 1941 + struct mt76_vif_link *mvif, 1945 1942 struct mt76_wcid *wcid, 1946 1943 bool enable); 1947 - int mt76_connac_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif *mvif, 1944 + int mt76_connac_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif_link *mvif, 1948 1945 struct ieee80211_ampdu_params *params, 1949 1946 int cmd, bool enable, bool tx); 1950 1947 int mt76_connac_mcu_uni_set_chctx(struct mt76_phy *phy, 1951 - struct mt76_vif *vif, 1948 + struct mt76_vif_link *vif, 1952 1949 struct ieee80211_chanctx_conf *ctx); 1953 1950 int mt76_connac_mcu_uni_add_bss(struct mt76_phy *phy, 1954 1951 struct ieee80211_vif *vif, ··· 1980 1975 struct ieee80211_vif *vif, 1981 1976 bool enable); 1982 1977 int mt76_connac_mcu_update_arp_filter(struct mt76_dev *dev, 1983 - struct mt76_vif *vif, 1978 + struct mt76_vif_link *vif, 1984 1979 struct ieee80211_bss_conf *info); 1985 1980 int mt76_connac_mcu_set_gtk_rekey(struct mt76_dev *dev, struct ieee80211_vif *vif, 1986 1981 bool suspend); ··· 1993 1988 struct ieee80211_vif *vif, 1994 1989 bool enable, u8 mdtim, 1995 1990 bool wow_suspend); 1996 - int mt76_connac_mcu_set_hif_suspend(struct mt76_dev *dev, bool suspend); 1991 + int mt76_connac_mcu_set_hif_suspend(struct mt76_dev *dev, bool suspend, bool wait_resp); 1997 1992 void mt76_connac_mcu_set_suspend_iter(void *priv, u8 *mac, 1998 1993 struct ieee80211_vif *vif); 1999 1994 int mt76_connac_sta_state_dp(struct mt76_dev *dev, ··· 2019 2014 u8 mt76_connac_get_phy_mode(struct mt76_phy *phy, struct ieee80211_vif *vif, 2020 2015 enum nl80211_band band, 2021 2016 struct ieee80211_link_sta *sta); 2022 - u8 mt76_connac_get_phy_mode_ext(struct mt76_phy *phy, struct ieee80211_vif *vif, 2017 + u8 mt76_connac_get_phy_mode_ext(struct mt76_phy *phy, struct ieee80211_bss_conf *conf, 2023 2018 enum nl80211_band band); 2024 2019 2025 2020 int mt76_connac_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif, ··· 2027 2022 struct ieee80211_key_conf *key, int mcu_cmd, 2028 2023 struct mt76_wcid *wcid, enum set_key_cmd cmd); 2029 2024 2030 - void mt76_connac_mcu_bss_ext_tlv(struct sk_buff *skb, struct mt76_vif *mvif); 2025 + void mt76_connac_mcu_bss_ext_tlv(struct sk_buff *skb, struct mt76_vif_link *mvif); 2031 2026 void mt76_connac_mcu_bss_omac_tlv(struct sk_buff *skb, 2032 2027 struct ieee80211_vif *vif); 2033 2028 int mt76_connac_mcu_bss_basic_tlv(struct sk_buff *skb,
+1 -1
drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
··· 1071 1071 u8 gain_delta; 1072 1072 int low_gain; 1073 1073 1074 - dev->cal.avg_rssi_all = mt76_get_min_avg_rssi(&dev->mt76, false); 1074 + dev->cal.avg_rssi_all = mt76_get_min_avg_rssi(&dev->mt76, 0); 1075 1075 if (!dev->cal.avg_rssi_all) 1076 1076 dev->cal.avg_rssi_all = -75; 1077 1077
+1 -1
drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c
··· 423 423 priv = msta->vif; 424 424 vif = container_of(priv, struct ieee80211_vif, drv_priv); 425 425 426 - __mt76_sta_remove(&dev->mt76, vif, sta); 426 + __mt76_sta_remove(&dev->mphy, vif, sta); 427 427 memset(msta, 0, sizeof(*msta)); 428 428 } 429 429
+1 -2
drivers/net/wireless/mediatek/mt76/mt76x02_util.c
··· 287 287 288 288 mvif->idx = idx; 289 289 mvif->group_wcid.idx = MT_VIF_WCID(idx); 290 - mvif->group_wcid.hw_key_idx = -1; 291 - mt76_wcid_init(&mvif->group_wcid); 290 + mt76_wcid_init(&mvif->group_wcid, 0); 292 291 293 292 mtxq = (struct mt76_txq *)vif->txq->drv_priv; 294 293 rcu_assign_pointer(dev->mt76.wcid[MT_VIF_WCID(idx)], &mvif->group_wcid);
+1 -1
drivers/net/wireless/mediatek/mt76/mt76x2/phy.c
··· 280 280 int low_gain; 281 281 u32 val; 282 282 283 - dev->cal.avg_rssi_all = mt76_get_min_avg_rssi(&dev->mt76, false); 283 + dev->cal.avg_rssi_all = mt76_get_min_avg_rssi(&dev->mt76, 0); 284 284 if (!dev->cal.avg_rssi_all) 285 285 dev->cal.avg_rssi_all = -75; 286 286
+19 -2
drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c
··· 2 2 /* Copyright (C) 2020 MediaTek Inc. */ 3 3 4 4 #include <linux/firmware.h> 5 + #include <linux/moduleparam.h> 5 6 #include "mt7915.h" 6 7 #include "eeprom.h" 8 + 9 + static bool enable_6ghz; 10 + module_param(enable_6ghz, bool, 0644); 11 + MODULE_PARM_DESC(enable_6ghz, "Enable 6 GHz instead of 5 GHz on hardware that supports both"); 7 12 8 13 static int mt7915_eeprom_load_precal(struct mt7915_dev *dev) 9 14 { ··· 175 170 phy->mt76->cap.has_6ghz = true; 176 171 return; 177 172 case MT_EE_V2_BAND_SEL_5GHZ_6GHZ: 178 - phy->mt76->cap.has_5ghz = true; 179 - phy->mt76->cap.has_6ghz = true; 173 + if (enable_6ghz) { 174 + phy->mt76->cap.has_6ghz = true; 175 + u8p_replace_bits(&eeprom[MT_EE_WIFI_CONF + band], 176 + MT_EE_V2_BAND_SEL_6GHZ, 177 + MT_EE_WIFI_CONF0_BAND_SEL); 178 + } else { 179 + phy->mt76->cap.has_5ghz = true; 180 + u8p_replace_bits(&eeprom[MT_EE_WIFI_CONF + band], 181 + MT_EE_V2_BAND_SEL_5GHZ, 182 + MT_EE_WIFI_CONF0_BAND_SEL); 183 + } 184 + /* force to buffer mode */ 185 + dev->flash_mode = true; 186 + 180 187 return; 181 188 default: 182 189 phy->mt76->cap.has_2ghz = true;
+18 -6
drivers/net/wireless/mediatek/mt76/mt7915/init.c
··· 53 53 54 54 switch (i) { 55 55 case 0: 56 + mutex_lock(&phy->dev->mt76.mutex); 56 57 temperature = mt7915_mcu_get_temperature(phy); 58 + mutex_unlock(&phy->dev->mt76.mutex); 57 59 if (temperature < 0) 58 60 return temperature; 59 61 /* display in millidegree celcius */ ··· 84 82 return ret; 85 83 86 84 mutex_lock(&phy->dev->mt76.mutex); 87 - val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 60, 130); 85 + val = DIV_ROUND_CLOSEST(clamp_val(val, 60 * 1000, 130 * 1000), 1000); 88 86 89 87 if ((i - 1 == MT7915_CRIT_TEMP_IDX && 90 88 val > phy->throttle_temp[MT7915_MAX_TEMP_IDX]) || ··· 97 95 } 98 96 99 97 phy->throttle_temp[i - 1] = val; 100 - mutex_unlock(&phy->dev->mt76.mutex); 101 - 102 98 ret = mt7915_mcu_set_thermal_protect(phy); 99 + mutex_unlock(&phy->dev->mt76.mutex); 103 100 if (ret) 104 101 return ret; 105 102 ··· 160 159 * cooling_device convention: 0 = no cooling, more = more cooling 161 160 * mcu convention: 1 = max cooling, more = less cooling 162 161 */ 162 + mutex_lock(&phy->dev->mt76.mutex); 163 163 ret = mt7915_mcu_set_thermal_throttling(phy, throttling); 164 + mutex_unlock(&phy->dev->mt76.mutex); 164 165 if (ret) 165 166 return ret; 166 167 ··· 514 511 MT_WF_RMAC_MIB_QOS01_BACKOFF); 515 512 mt76_clear(dev, MT_WF_RMAC_MIB_AIRTIME4(band), 516 513 MT_WF_RMAC_MIB_QOS23_BACKOFF); 514 + 515 + /* clear backoff time for Tx duration */ 516 + mt76_clear(dev, MT_WTBLOFF_TOP_ACR(band), 517 + MT_WTBLOFF_TOP_ADM_BACKOFFTIME); 518 + 519 + /* exclude estimated backoff time for Tx duration on MT7915 */ 520 + if (is_mt7915(&dev->mt76)) 521 + mt76_set(dev, MT_AGG_ATCR0(band), 522 + MT_AGG_ATCR_MAC_BFF_TIME_EN); 517 523 518 524 /* clear backoff time and set software compensation for OBSS time */ 519 525 mask = MT_WF_RMAC_MIB_OBSS_BACKOFF | MT_WF_RMAC_MIB_ED_OFFSET; ··· 1126 1114 memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres)); 1127 1115 if (he_cap_elem->phy_cap_info[6] & 1128 1116 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 1129 - mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss); 1117 + mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss, band); 1130 1118 } else { 1131 1119 he_cap_elem->phy_cap_info[9] |= 1132 1120 u8_encode_bits(IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US, ··· 1251 1239 if (ret) 1252 1240 goto unreg_dev; 1253 1241 1254 - ieee80211_queue_work(mt76_hw(dev), &dev->init_work); 1255 - 1256 1242 if (phy2) { 1257 1243 ret = mt7915_register_ext_phy(dev, phy2); 1258 1244 if (ret) 1259 1245 goto unreg_thermal; 1260 1246 } 1247 + 1248 + ieee80211_queue_work(mt76_hw(dev), &dev->init_work); 1261 1249 1262 1250 dev->recovery.hw_init_done = true; 1263 1251
+11 -15
drivers/net/wireless/mediatek/mt76/mt7915/mac.c
··· 333 333 334 334 if (status->wcid) { 335 335 msta = container_of(status->wcid, struct mt7915_sta, wcid); 336 - spin_lock_bh(&dev->mt76.sta_poll_lock); 337 - if (list_empty(&msta->wcid.poll_list)) 338 - list_add_tail(&msta->wcid.poll_list, 339 - &dev->mt76.sta_poll_list); 340 - spin_unlock_bh(&dev->mt76.sta_poll_lock); 336 + mt76_wcid_add_poll(&dev->mt76, &msta->wcid); 341 337 } 342 338 343 339 status->freq = mphy->chandef.chan->center_freq; ··· 923 927 continue; 924 928 925 929 msta = container_of(wcid, struct mt7915_sta, wcid); 926 - spin_lock_bh(&mdev->sta_poll_lock); 927 - if (list_empty(&msta->wcid.poll_list)) 928 - list_add_tail(&msta->wcid.poll_list, 929 - &mdev->sta_poll_list); 930 - spin_unlock_bh(&mdev->sta_poll_lock); 930 + mt76_wcid_add_poll(&dev->mt76, &msta->wcid); 931 931 continue; 932 932 } 933 933 ··· 1032 1040 if (!wcid->sta) 1033 1041 goto out; 1034 1042 1035 - spin_lock_bh(&dev->mt76.sta_poll_lock); 1036 - if (list_empty(&msta->wcid.poll_list)) 1037 - list_add_tail(&msta->wcid.poll_list, &dev->mt76.sta_poll_list); 1038 - spin_unlock_bh(&dev->mt76.sta_poll_lock); 1043 + mt76_wcid_add_poll(&dev->mt76, &msta->wcid); 1039 1044 1040 1045 out: 1041 1046 rcu_read_unlock(); ··· 1152 1163 u32 ofdm = FIELD_PREP(MT_TIMEOUT_VAL_PLCP, 60) | 1153 1164 FIELD_PREP(MT_TIMEOUT_VAL_CCA, 28); 1154 1165 u8 band = phy->mt76->band_idx; 1155 - int eifs_ofdm = 360, sifs = 10, offset; 1166 + int eifs_ofdm = 84, sifs = 10, offset; 1156 1167 bool a_band = !(phy->mt76->chandef.chan->band == NL80211_BAND_2GHZ); 1157 1168 1158 1169 if (!test_bit(MT76_STATE_RUNNING, &phy->mt76->state)) ··· 1377 1388 if (dev_is_pci(mdev->dev)) { 1378 1389 mt76_wr(dev, MT_PCIE_MAC_INT_ENABLE, 0xff); 1379 1390 if (dev->hif2) { 1391 + mt76_wr(dev, MT_PCIE_RECOG_ID, 1392 + dev->hif2->index | MT_PCIE_RECOG_ID_SEM); 1380 1393 if (is_mt7915(mdev)) 1381 1394 mt76_wr(dev, MT_PCIE1_MAC_INT_ENABLE, 0xff); 1382 1395 else ··· 1433 1442 mt7915_mac_full_reset(struct mt7915_dev *dev) 1434 1443 { 1435 1444 struct mt76_phy *ext_phy; 1445 + struct mt7915_phy *phy2; 1436 1446 int i; 1437 1447 1438 1448 ext_phy = dev->mt76.phys[MT_BAND1]; 1449 + phy2 = ext_phy ? ext_phy->priv : NULL; 1439 1450 1440 1451 dev->recovery.hw_full_reset = true; 1441 1452 ··· 1467 1474 1468 1475 memset(dev->mt76.wcid_mask, 0, sizeof(dev->mt76.wcid_mask)); 1469 1476 dev->mt76.vif_mask = 0; 1477 + dev->phy.omac_mask = 0; 1478 + if (phy2) 1479 + phy2->omac_mask = 0; 1470 1480 1471 1481 i = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA); 1472 1482 dev->mt76.global_wcid.idx = i;
+70 -9
drivers/net/wireless/mediatek/mt76/mt7915/main.c
··· 233 233 mvif->mt76.omac_idx = idx; 234 234 mvif->phy = phy; 235 235 mvif->mt76.band_idx = phy->mt76->band_idx; 236 + mvif->mt76.wcid = &mvif->sta.wcid; 236 237 237 238 mvif->mt76.wmm_idx = vif->type != NL80211_IFTYPE_AP; 238 239 if (ext_phy) ··· 247 246 phy->omac_mask |= BIT_ULL(mvif->mt76.omac_idx); 248 247 249 248 idx = mt76_wcid_alloc(dev->mt76.wcid_mask, mt7915_wtbl_size(dev)); 250 - if (idx < 0) 251 - return -ENOSPC; 249 + if (idx < 0) { 250 + ret = -ENOSPC; 251 + goto out; 252 + } 252 253 253 254 INIT_LIST_HEAD(&mvif->sta.rc_list); 254 - INIT_LIST_HEAD(&mvif->sta.wcid.poll_list); 255 255 mvif->sta.wcid.idx = idx; 256 - mvif->sta.wcid.phy_idx = ext_phy; 257 - mvif->sta.wcid.hw_key_idx = -1; 258 256 mvif->sta.wcid.tx_info |= MT_WCID_TX_INFO_SET; 259 - mt76_wcid_init(&mvif->sta.wcid); 257 + mt76_wcid_init(&mvif->sta.wcid, phy->mt76->band_idx); 260 258 261 259 mt7915_mac_wtbl_update(dev, idx, 262 260 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); ··· 366 366 int idx = key->keyidx; 367 367 int err = 0; 368 368 369 - if (sta && !wcid->sta) 369 + if (sta && !wcid->sta) { 370 + if (cmd != SET_KEY) 371 + return 0; 372 + 370 373 return -EOPNOTSUPP; 374 + } 371 375 372 376 /* The hardware does not support per-STA RX GTK, fallback 373 377 * to software mode for these. ··· 623 619 if (changed & BSS_CHANGED_ASSOC) 624 620 set_bss_info = vif->cfg.assoc; 625 621 if (changed & BSS_CHANGED_BEACON_ENABLED && 622 + info->enable_beacon && 626 623 vif->type != NL80211_IFTYPE_AP) 627 - set_bss_info = set_sta = info->enable_beacon; 624 + set_bss_info = set_sta = 1; 628 625 629 626 if (set_bss_info == 1) 630 627 mt7915_mcu_add_bss_info(phy, vif, true); ··· 636 631 mt7915_mac_enable_rtscts(dev, vif, info->use_cts_prot); 637 632 638 633 if (changed & BSS_CHANGED_ERP_SLOT) { 639 - int slottime = info->use_short_slot ? 9 : 20; 634 + int slottime = 9; 635 + 636 + if (phy->mt76->chandef.chan->band == NL80211_BAND_2GHZ && 637 + !info->use_short_slot) 638 + slottime = 20; 640 639 641 640 if (slottime != phy->slottime) { 642 641 phy->slottime = slottime; ··· 767 758 return 0; 768 759 } 769 760 761 + struct drop_sta_iter { 762 + struct mt7915_dev *dev; 763 + struct ieee80211_hw *hw; 764 + struct ieee80211_vif *vif; 765 + u8 sta_addr[ETH_ALEN]; 766 + }; 767 + 768 + static void 769 + __mt7915_drop_sta(void *ptr, u8 *mac, struct ieee80211_vif *vif) 770 + { 771 + struct drop_sta_iter *data = ptr; 772 + struct ieee80211_sta *sta; 773 + struct mt7915_sta *msta; 774 + 775 + if (vif == data->vif || vif->type != NL80211_IFTYPE_AP) 776 + return; 777 + 778 + sta = ieee80211_find_sta_by_ifaddr(data->hw, data->sta_addr, mac); 779 + if (!sta) 780 + return; 781 + 782 + msta = (struct mt7915_sta *)sta->drv_priv; 783 + mt7915_mcu_add_sta(data->dev, vif, sta, CONN_STATE_DISCONNECT, false); 784 + msta->wcid.sta_disabled = 1; 785 + msta->wcid.sta = 0; 786 + } 787 + 788 + static void 789 + mt7915_drop_other_sta(struct mt7915_dev *dev, struct ieee80211_vif *vif, 790 + struct ieee80211_sta *sta) 791 + { 792 + struct mt76_phy *ext_phy = dev->mt76.phys[MT_BAND1]; 793 + struct drop_sta_iter data = { 794 + .dev = dev, 795 + .hw = dev->mphy.hw, 796 + .vif = vif, 797 + }; 798 + 799 + if (vif->type != NL80211_IFTYPE_AP) 800 + return; 801 + 802 + memcpy(data.sta_addr, sta->addr, ETH_ALEN); 803 + ieee80211_iterate_active_interfaces(data.hw, 0, __mt7915_drop_sta, &data); 804 + 805 + if (!ext_phy) 806 + return; 807 + 808 + data.hw = ext_phy->hw; 809 + ieee80211_iterate_active_interfaces(data.hw, 0, __mt7915_drop_sta, &data); 810 + } 811 + 770 812 int mt7915_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif, 771 813 struct ieee80211_sta *sta, enum mt76_sta_event ev) 772 814 { ··· 846 786 return 0; 847 787 848 788 case MT76_STA_EVENT_AUTHORIZE: 789 + mt7915_drop_other_sta(dev, vif, sta); 849 790 return mt7915_mcu_add_sta(dev, vif, sta, CONN_STATE_PORT_SECURE, false); 850 791 851 792 case MT76_STA_EVENT_DISASSOC:
+30 -4
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
··· 194 194 return ret; 195 195 } 196 196 197 + static void 198 + mt7915_mcu_set_timeout(struct mt76_dev *mdev, int cmd) 199 + { 200 + if ((cmd & __MCU_CMD_FIELD_ID) != MCU_CMD_EXT_CID) 201 + return; 202 + 203 + switch (FIELD_GET(__MCU_CMD_FIELD_EXT_ID, cmd)) { 204 + case MCU_EXT_CMD_THERMAL_CTRL: 205 + case MCU_EXT_CMD_GET_MIB_INFO: 206 + case MCU_EXT_CMD_PHY_STAT_INFO: 207 + case MCU_EXT_CMD_STA_REC_UPDATE: 208 + case MCU_EXT_CMD_BSS_INFO_UPDATE: 209 + mdev->mcu.timeout = 2 * HZ; 210 + return; 211 + default: 212 + break; 213 + } 214 + } 215 + 197 216 static int 198 217 mt7915_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb, 199 218 int cmd, int *wait_seq) ··· 226 207 qid = MT_MCUQ_WA; 227 208 else 228 209 qid = MT_MCUQ_WM; 210 + 211 + mt7915_mcu_set_timeout(mdev, cmd); 229 212 230 213 return mt76_tx_queue_skb_raw(dev, mdev->q_mcu[qid], skb, 0); 231 214 } ··· 1699 1678 return PTR_ERR(skb); 1700 1679 1701 1680 /* starec basic */ 1702 - mt76_connac_mcu_sta_basic_tlv(&dev->mt76, skb, vif, link_sta, 1681 + mt76_connac_mcu_sta_basic_tlv(&dev->mt76, skb, &vif->bss_conf, link_sta, 1703 1682 conn_state, newly); 1704 1683 /* tag order is in accordance with firmware dependency. */ 1705 1684 if (sta && conn_state != CONN_STATE_DISCONNECT) { ··· 2409 2388 int mt7915_mcu_init(struct mt7915_dev *dev) 2410 2389 { 2411 2390 static const struct mt76_mcu_ops mt7915_mcu_ops = { 2412 - .max_retry = 3, 2391 + .max_retry = 1, 2413 2392 .headroom = sizeof(struct mt76_connac2_mcu_txd), 2414 2393 .mcu_skb_prepare_msg = mt76_connac2_mcu_fill_message, 2415 2394 .mcu_skb_send_msg = mt7915_mcu_send_message, ··· 3171 3150 res = (struct mt7915_mcu_mib *)(skb->data + offs_cc); 3172 3151 3173 3152 #define __res_u64(s) le64_to_cpu(res[s].data) 3174 - /* subtract Tx backoff time from Tx duration */ 3175 - cc_tx = is_mt7915(&dev->mt76) ? __res_u64(1) - __res_u64(4) : __res_u64(1); 3153 + /* subtract Tx backoff time from Tx duration for MT7915 */ 3154 + if (is_mt7915(&dev->mt76)) { 3155 + u64 backoff = (__res_u64(4) & 0xffff) * 79; /* 16us + 9us * 7 */ 3156 + cc_tx = __res_u64(1) - backoff; 3157 + } else { 3158 + cc_tx = __res_u64(1); 3159 + } 3176 3160 3177 3161 if (chan_switch) 3178 3162 goto out;
+3 -1
drivers/net/wireless/mediatek/mt76/mt7915/mmio.c
··· 138 138 [AGG_ACR0] = 0x084, 139 139 [AGG_ACR4] = 0x08c, 140 140 [AGG_MRCR] = 0x098, 141 + [AGG_ATCR0] = 0x0ec, 141 142 [AGG_ATCR1] = 0x0f0, 142 143 [AGG_ATCR3] = 0x0f4, 143 144 [LPON_UTTR0] = 0x080, ··· 213 212 [AGG_ACR0] = 0x054, 214 213 [AGG_ACR4] = 0x05c, 215 214 [AGG_MRCR] = 0x068, 215 + [AGG_ATCR0] = 0x1a4, 216 216 [AGG_ATCR1] = 0x1a8, 217 217 [AGG_ATCR3] = 0x080, 218 218 [LPON_UTTR0] = 0x360, ··· 486 484 continue; 487 485 488 486 ofs = addr - dev->reg.map[i].phys; 489 - if (ofs > dev->reg.map[i].size) 487 + if (ofs >= dev->reg.map[i].size) 490 488 continue; 491 489 492 490 return dev->reg.map[i].maps + ofs;
+2 -1
drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
··· 166 166 }; 167 167 168 168 struct mt7915_vif { 169 - struct mt76_vif mt76; /* must be first */ 169 + struct mt76_vif_link mt76; /* must be first */ 170 170 171 171 struct mt7915_vif_cap cap; 172 172 struct mt7915_sta sta; ··· 191 191 struct device *dev; 192 192 void __iomem *regs; 193 193 int irq; 194 + u32 index; 194 195 }; 195 196 196 197 struct mt7915_phy {
+1
drivers/net/wireless/mediatek/mt76/mt7915/pci.c
··· 42 42 continue; 43 43 44 44 get_device(hif->dev); 45 + hif->index = idx; 45 46 goto out; 46 47 } 47 48 hif = NULL;
+7
drivers/net/wireless/mediatek/mt76/mt7915/regs.h
··· 66 66 AGG_ACR0, 67 67 AGG_ACR4, 68 68 AGG_MRCR, 69 + AGG_ATCR0, 69 70 AGG_ATCR1, 70 71 AGG_ATCR3, 71 72 LPON_UTTR0, ··· 254 253 #define MT_WTBLOFF_TOP_RSCR(_band) MT_WTBLOFF_TOP(_band, 0x008) 255 254 #define MT_WTBLOFF_TOP_RSCR_RCPI_MODE GENMASK(31, 30) 256 255 #define MT_WTBLOFF_TOP_RSCR_RCPI_PARAM GENMASK(25, 24) 256 + 257 + #define MT_WTBLOFF_TOP_ACR(_band) MT_WTBLOFF_TOP(_band, 0x010) 258 + #define MT_WTBLOFF_TOP_ADM_BACKOFFTIME BIT(29) 257 259 258 260 /* ETBF: band 0(0x820ea000), band 1(0x820fa000) */ 259 261 #define MT_WF_ETBF_BASE(_band) ((_band) ? 0x820fa000 : 0x820ea000) ··· 508 504 #define MT_AGG_MRCR_LAST_RTS_CTS_RN BIT(6) 509 505 #define MT_AGG_MRCR_RTS_FAIL_LIMIT GENMASK(11, 7) 510 506 #define MT_AGG_MRCR_TXCMD_RTS_FAIL_LIMIT GENMASK(28, 24) 507 + 508 + #define MT_AGG_ATCR0(_band) MT_WF_AGG(_band, __OFFS(AGG_ATCR0)) 509 + #define MT_AGG_ATCR_MAC_BFF_TIME_EN BIT(30) 511 510 512 511 #define MT_AGG_ATCR1(_band) MT_WF_AGG(_band, __OFFS(AGG_ATCR1)) 513 512 #define MT_AGG_ATCR3(_band) MT_WF_AGG(_band, __OFFS(AGG_ATCR3))
+8
drivers/net/wireless/mediatek/mt76/mt7921/init.c
··· 137 137 dev->mt76.region = request->dfs_region; 138 138 dev->country_ie_env = request->country_ie_env; 139 139 140 + if (request->initiator == NL80211_REGDOM_SET_BY_USER) { 141 + if (dev->mt76.alpha2[0] == '0' && dev->mt76.alpha2[1] == '0') 142 + wiphy->regulatory_flags &= ~REGULATORY_COUNTRY_IE_IGNORE; 143 + else 144 + wiphy->regulatory_flags |= REGULATORY_COUNTRY_IE_IGNORE; 145 + } 146 + 140 147 if (pm->suspended) 141 148 return; 142 149 ··· 234 227 235 228 mt76_set_stream_caps(&dev->mphy, true); 236 229 mt7921_set_stream_he_caps(&dev->phy); 230 + mt792x_config_mac_addr_list(dev); 237 231 238 232 ret = mt76_register_device(&dev->mt76, true, mt76_rates, 239 233 ARRAY_SIZE(mt76_rates));
+4 -14
drivers/net/wireless/mediatek/mt76/mt7921/mac.c
··· 216 216 if (status->wcid) { 217 217 mlink = container_of(status->wcid, struct mt792x_link_sta, wcid); 218 218 msta = container_of(mlink, struct mt792x_sta, deflink); 219 - spin_lock_bh(&dev->mt76.sta_poll_lock); 220 - if (list_empty(&mlink->wcid.poll_list)) 221 - list_add_tail(&mlink->wcid.poll_list, 222 - &dev->mt76.sta_poll_list); 223 - spin_unlock_bh(&dev->mt76.sta_poll_lock); 219 + mt76_wcid_add_poll(&dev->mt76, &mlink->wcid); 224 220 } 225 221 226 222 mt792x_get_status_freq_info(status, chfreq); ··· 475 479 if (!wcid->sta) 476 480 goto out; 477 481 478 - spin_lock_bh(&dev->mt76.sta_poll_lock); 479 - if (list_empty(&mlink->wcid.poll_list)) 480 - list_add_tail(&mlink->wcid.poll_list, &dev->mt76.sta_poll_list); 481 - spin_unlock_bh(&dev->mt76.sta_poll_lock); 482 + mt76_wcid_add_poll(&dev->mt76, &mlink->wcid); 482 483 483 484 out: 484 485 rcu_read_unlock(); ··· 522 529 continue; 523 530 524 531 mlink = container_of(wcid, struct mt792x_link_sta, wcid); 525 - spin_lock_bh(&mdev->sta_poll_lock); 526 - if (list_empty(&mlink->wcid.poll_list)) 527 - list_add_tail(&mlink->wcid.poll_list, 528 - &mdev->sta_poll_list); 529 - spin_unlock_bh(&mdev->sta_poll_lock); 532 + mt76_wcid_add_poll(&dev->mt76, &mlink->wcid); 530 533 continue; 531 534 } 532 535 ··· 636 647 ieee80211_disconnect(vif, true); 637 648 638 649 mt76_connac_mcu_uni_add_dev(&dev->mphy, &vif->bss_conf, 650 + &mvif->bss_conf.mt76, 639 651 &mvif->sta.deflink.wcid, true); 640 652 mt7921_mcu_set_tx(dev, vif); 641 653
+130 -8
drivers/net/wireless/mediatek/mt76/mt7921/main.c
··· 147 147 memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres)); 148 148 if (he_cap_elem->phy_cap_info[6] & 149 149 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 150 - mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss); 150 + mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss, band); 151 151 } else { 152 152 he_cap_elem->phy_cap_info[9] |= 153 153 u8_encode_bits(IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US, ··· 252 252 return err; 253 253 } 254 254 255 + if (phy->chip_cap & MT792x_CHIP_CAP_WF_RF_PIN_CTRL_EVT_EN) { 256 + mt7921_mcu_wf_rf_pin_ctrl(phy, WF_RF_PIN_INIT); 257 + wiphy_rfkill_start_polling(mphy->hw->wiphy); 258 + } 259 + 255 260 return 0; 256 261 } 257 262 EXPORT_SYMBOL_GPL(__mt7921_start); ··· 313 308 mvif->bss_conf.mt76.wmm_idx = mvif->bss_conf.mt76.idx % MT76_CONNAC_MAX_WMM_SETS; 314 309 315 310 ret = mt76_connac_mcu_uni_add_dev(&dev->mphy, &vif->bss_conf, 311 + &mvif->bss_conf.mt76, 316 312 &mvif->sta.deflink.wcid, true); 317 313 if (ret) 318 314 goto out; ··· 325 319 326 320 INIT_LIST_HEAD(&mvif->sta.deflink.wcid.poll_list); 327 321 mvif->sta.deflink.wcid.idx = idx; 328 - mvif->sta.deflink.wcid.phy_idx = mvif->bss_conf.mt76.band_idx; 329 - mvif->sta.deflink.wcid.hw_key_idx = -1; 330 322 mvif->sta.deflink.wcid.tx_info |= MT_WCID_TX_INFO_SET; 331 - mt76_wcid_init(&mvif->sta.deflink.wcid); 323 + mt76_wcid_init(&mvif->sta.deflink.wcid, mvif->bss_conf.mt76.band_idx); 332 324 333 325 mt7921_mac_wtbl_update(dev, idx, 334 326 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); ··· 342 338 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER; 343 339 if (phy->chip_cap & MT792x_CHIP_CAP_RSSI_NOTIFY_EVT_EN) 344 340 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_CQM_RSSI; 341 + 342 + INIT_WORK(&mvif->csa_work, mt7921_csa_work); 343 + timer_setup(&mvif->csa_timer, mt792x_csa_timer, 0); 345 344 out: 346 345 mt792x_mutex_release(dev); 347 346 ··· 367 360 del_timer_sync(&phy->roc_timer); 368 361 cancel_work_sync(&phy->roc_work); 369 362 if (test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state)) 370 - ieee80211_iterate_active_interfaces(mt76_hw(dev), 371 - IEEE80211_IFACE_ITER_RESUME_ALL, 372 - mt7921_roc_iter, (void *)phy); 363 + ieee80211_iterate_interfaces(mt76_hw(dev), 364 + IEEE80211_IFACE_ITER_RESUME_ALL, 365 + mt7921_roc_iter, (void *)phy); 373 366 } 374 367 EXPORT_SYMBOL_GPL(mt7921_roc_abort_sync); 375 368 ··· 538 531 } else { 539 532 if (idx == *wcid_keyidx) 540 533 *wcid_keyidx = -1; 541 - goto out; 534 + 535 + /* For security issue we don't trigger the key deletion when 536 + * reassociating. But we should trigger the deletion process 537 + * to avoid using incorrect cipher after disconnection, 538 + */ 539 + if (vif->type != NL80211_IFTYPE_STATION || vif->cfg.assoc) 540 + goto out; 542 541 } 543 542 544 543 mt76_wcid_key_setup(&dev->mt76, wcid, key); ··· 871 858 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); 872 859 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; 873 860 861 + mt7921_roc_abort_sync(dev); 874 862 mt76_connac_free_pending_tx_skbs(&dev->pm, &msta->deflink.wcid); 875 863 mt76_connac_pm_wake(&dev->mphy, &dev->pm); 876 864 ··· 1348 1334 mt7921_add_chanctx(struct ieee80211_hw *hw, 1349 1335 struct ieee80211_chanctx_conf *ctx) 1350 1336 { 1337 + struct mt792x_dev *dev = mt792x_hw_dev(hw); 1338 + 1339 + dev->new_ctx = ctx; 1351 1340 return 0; 1352 1341 } 1353 1342 ··· 1358 1341 mt7921_remove_chanctx(struct ieee80211_hw *hw, 1359 1342 struct ieee80211_chanctx_conf *ctx) 1360 1343 { 1344 + struct mt792x_dev *dev = mt792x_hw_dev(hw); 1345 + 1346 + if (dev->new_ctx == ctx) 1347 + dev->new_ctx = NULL; 1361 1348 } 1362 1349 1363 1350 static void ··· 1410 1389 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1411 1390 1412 1391 mt7921_abort_roc(mvif->phy, mvif); 1392 + } 1393 + 1394 + static int mt7921_switch_vif_chanctx(struct ieee80211_hw *hw, 1395 + struct ieee80211_vif_chanctx_switch *vifs, 1396 + int n_vifs, 1397 + enum ieee80211_chanctx_switch_mode mode) 1398 + { 1399 + return mt792x_assign_vif_chanctx(hw, vifs->vif, vifs->link_conf, 1400 + vifs->new_ctx); 1401 + } 1402 + 1403 + void mt7921_csa_work(struct work_struct *work) 1404 + { 1405 + struct mt792x_vif *mvif; 1406 + struct mt792x_dev *dev; 1407 + struct ieee80211_vif *vif; 1408 + int ret; 1409 + 1410 + mvif = (struct mt792x_vif *)container_of(work, struct mt792x_vif, 1411 + csa_work); 1412 + dev = mvif->phy->dev; 1413 + vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv); 1414 + 1415 + mt792x_mutex_acquire(dev); 1416 + ret = mt76_connac_mcu_uni_set_chctx(mvif->phy->mt76, &mvif->bss_conf.mt76, 1417 + dev->new_ctx); 1418 + mt792x_mutex_release(dev); 1419 + 1420 + ieee80211_chswitch_done(vif, !ret, 0); 1421 + } 1422 + 1423 + static int mt7921_pre_channel_switch(struct ieee80211_hw *hw, 1424 + struct ieee80211_vif *vif, 1425 + struct ieee80211_channel_switch *chsw) 1426 + { 1427 + if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc) 1428 + return -EOPNOTSUPP; 1429 + 1430 + /* Avoid beacon loss due to the CAC(Channel Availability Check) time 1431 + * of the AP. 1432 + */ 1433 + if (!cfg80211_chandef_usable(hw->wiphy, &chsw->chandef, 1434 + IEEE80211_CHAN_RADAR)) 1435 + return -EOPNOTSUPP; 1436 + 1437 + return 0; 1438 + } 1439 + 1440 + static void mt7921_channel_switch(struct ieee80211_hw *hw, 1441 + struct ieee80211_vif *vif, 1442 + struct ieee80211_channel_switch *chsw) 1443 + { 1444 + struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1445 + u16 beacon_interval = vif->bss_conf.beacon_int; 1446 + 1447 + mvif->csa_timer.expires = TU_TO_EXP_TIME(beacon_interval * chsw->count); 1448 + add_timer(&mvif->csa_timer); 1449 + } 1450 + 1451 + static void mt7921_abort_channel_switch(struct ieee80211_hw *hw, 1452 + struct ieee80211_vif *vif, 1453 + struct ieee80211_bss_conf *link_conf) 1454 + { 1455 + struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1456 + 1457 + del_timer_sync(&mvif->csa_timer); 1458 + cancel_work_sync(&mvif->csa_work); 1459 + } 1460 + 1461 + static void mt7921_channel_switch_rx_beacon(struct ieee80211_hw *hw, 1462 + struct ieee80211_vif *vif, 1463 + struct ieee80211_channel_switch *chsw) 1464 + { 1465 + struct mt792x_dev *dev = mt792x_hw_dev(hw); 1466 + struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 1467 + u16 beacon_interval = vif->bss_conf.beacon_int; 1468 + 1469 + if (cfg80211_chandef_identical(&chsw->chandef, 1470 + &dev->new_ctx->def) && 1471 + chsw->count) { 1472 + mod_timer(&mvif->csa_timer, 1473 + TU_TO_EXP_TIME(beacon_interval * chsw->count)); 1474 + } 1475 + } 1476 + 1477 + static void mt7921_rfkill_poll(struct ieee80211_hw *hw) 1478 + { 1479 + struct mt792x_phy *phy = mt792x_hw_phy(hw); 1480 + int ret = 0; 1481 + 1482 + mt792x_mutex_acquire(phy->dev); 1483 + ret = mt7921_mcu_wf_rf_pin_ctrl(phy, WF_RF_PIN_POLL); 1484 + mt792x_mutex_release(phy->dev); 1485 + 1486 + wiphy_rfkill_set_hw_state(hw->wiphy, ret ? false : true); 1413 1487 } 1414 1488 1415 1489 const struct ieee80211_ops mt7921_ops = { ··· 1557 1441 #endif /* CONFIG_PM */ 1558 1442 .flush = mt792x_flush, 1559 1443 .set_sar_specs = mt7921_set_sar_specs, 1444 + .rfkill_poll = mt7921_rfkill_poll, 1560 1445 .remain_on_channel = mt7921_remain_on_channel, 1561 1446 .cancel_remain_on_channel = mt7921_cancel_remain_on_channel, 1562 1447 .add_chanctx = mt7921_add_chanctx, ··· 1567 1450 .unassign_vif_chanctx = mt792x_unassign_vif_chanctx, 1568 1451 .mgd_prepare_tx = mt7921_mgd_prepare_tx, 1569 1452 .mgd_complete_tx = mt7921_mgd_complete_tx, 1453 + .switch_vif_chanctx = mt7921_switch_vif_chanctx, 1454 + .pre_channel_switch = mt7921_pre_channel_switch, 1455 + .channel_switch = mt7921_channel_switch, 1456 + .abort_channel_switch = mt7921_abort_channel_switch, 1457 + .channel_switch_rx_beacon = mt7921_channel_switch_rx_beacon, 1570 1458 }; 1571 1459 EXPORT_SYMBOL_GPL(mt7921_ops); 1572 1460
+27 -3
drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
··· 61 61 skb_pull(skb, sizeof(*rxd)); 62 62 event = (struct mt76_connac_mcu_reg_event *)skb->data; 63 63 ret = (int)le32_to_cpu(event->val); 64 + } else if (cmd == MCU_EXT_CMD(WF_RF_PIN_CTRL)) { 65 + struct mt7921_wf_rf_pin_ctrl_event *event; 66 + 67 + skb_pull(skb, sizeof(*rxd)); 68 + event = (struct mt7921_wf_rf_pin_ctrl_event *)skb->data; 69 + ret = (int)event->result; 64 70 } else { 65 71 skb_pull(skb, sizeof(struct mt76_connac2_mcu_rxd)); 66 72 } ··· 180 174 mt7921_mcu_connection_loss_iter(void *priv, u8 *mac, 181 175 struct ieee80211_vif *vif) 182 176 { 183 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 177 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 184 178 struct mt76_connac_beacon_loss_event *event = priv; 185 179 186 180 if (mvif->idx != event->bss_idx) ··· 513 507 514 508 tx_res = (struct mt7921_tx_resource *)skb->data; 515 509 sdio->sched.pse_data_quota = le32_to_cpu(tx_res->pse_data_quota); 516 - sdio->sched.pse_mcu_quota = le32_to_cpu(tx_res->pse_mcu_quota); 510 + sdio->pse_mcu_quota_max = le32_to_cpu(tx_res->pse_mcu_quota); 511 + /* The mcu quota usage of this function itself must be taken into consideration */ 512 + sdio->sched.pse_mcu_quota = 513 + sdio->sched.pse_mcu_quota ? sdio->pse_mcu_quota_max : sdio->pse_mcu_quota_max - 1; 517 514 sdio->sched.ple_data_quota = le32_to_cpu(tx_res->ple_data_quota); 518 515 sdio->sched.pse_page_size = le16_to_cpu(tx_res->pse_page_size); 519 516 sdio->sched.deficit = tx_res->pp_padding; ··· 1131 1122 int mt7921_mcu_set_sniffer(struct mt792x_dev *dev, struct ieee80211_vif *vif, 1132 1123 bool enable) 1133 1124 { 1134 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 1125 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 1135 1126 struct { 1136 1127 struct { 1137 1128 u8 band_idx; ··· 1431 1422 1432 1423 return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_CTRL), &req, 1433 1424 sizeof(req), true); 1425 + } 1426 + 1427 + int mt7921_mcu_wf_rf_pin_ctrl(struct mt792x_phy *phy, u8 action) 1428 + { 1429 + struct mt792x_dev *dev = phy->dev; 1430 + struct { 1431 + u8 action; 1432 + u8 value; 1433 + } req = { 1434 + .action = action, 1435 + .value = 0, 1436 + }; 1437 + 1438 + return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(WF_RF_PIN_CTRL), &req, 1439 + sizeof(req), action ? true : false); 1434 1440 } 1435 1441 1436 1442 int mt7921_mcu_set_rxfilter(struct mt792x_dev *dev, u32 fif,
+5
drivers/net/wireless/mediatek/mt76/mt7921/mcu.h
··· 74 74 struct mt7921_txpwr txpwr; 75 75 } __packed; 76 76 77 + struct mt7921_wf_rf_pin_ctrl_event { 78 + u8 result; 79 + u8 value; 80 + } __packed; 81 + 77 82 enum { 78 83 TM_SWITCH_MODE, 79 84 TM_SET_AT_CMD,
+5
drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
··· 31 31 #define EXT_CMD_RADIO_ON_LED 0x2 32 32 #define EXT_CMD_RADIO_OFF_LED 0x3 33 33 34 + #define WF_RF_PIN_INIT 0x0 35 + #define WF_RF_PIN_POLL 0x1 36 + 34 37 enum { 35 38 UNI_ROC_ACQUIRE, 36 39 UNI_ROC_ABORT, ··· 205 202 int mt7921_mcu_set_rxfilter(struct mt792x_dev *dev, u32 fif, 206 203 u8 bit_op, u32 bit_map); 207 204 int mt7921_mcu_radio_led_ctrl(struct mt792x_dev *dev, u8 value); 205 + int mt7921_mcu_wf_rf_pin_ctrl(struct mt792x_phy *phy, u8 action); 208 206 209 207 static inline u32 210 208 mt7921_reg_map_l1(struct mt792x_dev *dev, u32 addr) ··· 277 273 bool enable); 278 274 void mt7921_scan_work(struct work_struct *work); 279 275 void mt7921_roc_work(struct work_struct *work); 276 + void mt7921_csa_work(struct work_struct *work); 280 277 int mt7921_mcu_uni_bss_ps(struct mt792x_dev *dev, struct ieee80211_vif *vif); 281 278 void mt7921_coredump_work(struct work_struct *work); 282 279 int mt7921_get_txpwr_info(struct mt792x_dev *dev, struct mt7921_txpwr *txpwr);
+7 -3
drivers/net/wireless/mediatek/mt76/mt7921/pci.c
··· 42 42 { 43 43 int i; 44 44 struct mt76_connac_pm *pm = &dev->pm; 45 + struct ieee80211_hw *hw = mt76_hw(dev); 46 + 47 + if (dev->phy.chip_cap & MT792x_CHIP_CAP_WF_RF_PIN_CTRL_EVT_EN) 48 + wiphy_rfkill_stop_polling(hw->wiphy); 45 49 46 50 cancel_work_sync(&dev->init_work); 47 51 mt76_unregister_device(&dev->mt76); ··· 439 435 if (err < 0) 440 436 goto restore_suspend; 441 437 442 - err = mt76_connac_mcu_set_hif_suspend(mdev, true); 438 + err = mt76_connac_mcu_set_hif_suspend(mdev, true, true); 443 439 if (err) 444 440 goto restore_suspend; 445 441 ··· 485 481 if (!pm->ds_enable) 486 482 mt76_connac_mcu_set_deep_sleep(&dev->mt76, false); 487 483 488 - mt76_connac_mcu_set_hif_suspend(mdev, false); 484 + mt76_connac_mcu_set_hif_suspend(mdev, false, true); 489 485 490 486 restore_suspend: 491 487 pm->suspended = false; ··· 536 532 if (!pm->ds_enable) 537 533 mt76_connac_mcu_set_deep_sleep(&dev->mt76, false); 538 534 539 - err = mt76_connac_mcu_set_hif_suspend(mdev, false); 535 + err = mt76_connac_mcu_set_hif_suspend(mdev, false, true); 540 536 if (err < 0) 541 537 goto failed; 542 538
+3 -3
drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
··· 240 240 mt76s_txqs_empty(&dev->mt76), 5 * HZ); 241 241 242 242 /* It is supposed that SDIO bus is idle at the point */ 243 - err = mt76_connac_mcu_set_hif_suspend(mdev, true); 243 + err = mt76_connac_mcu_set_hif_suspend(mdev, true, true); 244 244 if (err) 245 245 goto restore_worker; 246 246 ··· 258 258 restore_txrx_worker: 259 259 mt76_worker_enable(&mdev->sdio.net_worker); 260 260 mt76_worker_enable(&mdev->sdio.txrx_worker); 261 - mt76_connac_mcu_set_hif_suspend(mdev, false); 261 + mt76_connac_mcu_set_hif_suspend(mdev, false, true); 262 262 263 263 restore_worker: 264 264 mt76_worker_enable(&mdev->tx_worker); ··· 302 302 if (!pm->ds_enable) 303 303 mt76_connac_mcu_set_deep_sleep(mdev, false); 304 304 305 - err = mt76_connac_mcu_set_hif_suspend(mdev, false); 305 + err = mt76_connac_mcu_set_hif_suspend(mdev, false, true); 306 306 failed: 307 307 pm->suspended = false; 308 308
+5 -2
drivers/net/wireless/mediatek/mt76/mt7921/usb.c
··· 21 21 /* Netgear, Inc. [A8000,AXE3000] */ 22 22 { USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0x9060, 0xff, 0xff, 0xff), 23 23 .driver_info = (kernel_ulong_t)MT7921_FIRMWARE_WM }, 24 + /* TP-Link TXE50UH */ 25 + { USB_DEVICE_AND_INTERFACE_INFO(0x35bc, 0x0107, 0xff, 0xff, 0xff), 26 + .driver_info = (kernel_ulong_t)MT7921_FIRMWARE_WM }, 24 27 { }, 25 28 }; 26 29 ··· 260 257 pm->suspended = true; 261 258 flush_work(&dev->reset_work); 262 259 263 - err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, true); 260 + err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, true, true); 264 261 if (err) 265 262 goto failed; 266 263 ··· 310 307 if (err < 0) 311 308 goto failed; 312 309 313 - err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, false); 310 + err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, false, true); 314 311 failed: 315 312 pm->suspended = false; 316 313
+27 -3
drivers/net/wireless/mediatek/mt76/mt7925/init.c
··· 57 57 mt7925_hwmon_groups); 58 58 return PTR_ERR_OR_ZERO(hwmon); 59 59 } 60 + 61 + void mt7925_regd_update(struct mt792x_dev *dev) 62 + { 63 + struct mt76_dev *mdev = &dev->mt76; 64 + struct ieee80211_hw *hw = mdev->hw; 65 + 66 + if (!dev->regd_change) 67 + return; 68 + 69 + mt7925_mcu_set_clc(dev, mdev->alpha2, dev->country_ie_env); 70 + mt7925_mcu_set_channel_domain(hw->priv); 71 + mt7925_set_tx_sar_pwr(hw, NULL); 72 + dev->regd_change = false; 73 + } 74 + EXPORT_SYMBOL_GPL(mt7925_regd_update); 75 + 60 76 static void 61 77 mt7925_regd_notifier(struct wiphy *wiphy, 62 78 struct regulatory_request *req) ··· 80 64 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 81 65 struct mt792x_dev *dev = mt792x_hw_dev(hw); 82 66 struct mt76_dev *mdev = &dev->mt76; 67 + struct mt76_connac_pm *pm = &dev->pm; 83 68 84 69 /* allow world regdom at the first boot only */ 85 70 if (!memcmp(req->alpha2, "00", 2) && ··· 95 78 memcpy(mdev->alpha2, req->alpha2, 2); 96 79 mdev->region = req->dfs_region; 97 80 dev->country_ie_env = req->country_ie_env; 81 + dev->regd_change = true; 98 82 83 + if (pm->suspended) 84 + return; 85 + 86 + dev->regd_in_progress = true; 99 87 mt792x_mutex_acquire(dev); 100 - mt7925_mcu_set_clc(dev, req->alpha2, req->country_ie_env); 101 - mt7925_mcu_set_channel_domain(hw->priv); 102 - mt7925_set_tx_sar_pwr(hw, NULL); 88 + mt7925_regd_update(dev); 103 89 mt792x_mutex_release(dev); 90 + dev->regd_in_progress = false; 91 + wake_up(&dev->wait); 104 92 } 105 93 106 94 static void mt7925_mac_init_basic_rates(struct mt792x_dev *dev) ··· 200 178 201 179 mt76_set_stream_caps(&dev->mphy, true); 202 180 mt7925_set_stream_he_eht_caps(&dev->phy); 181 + mt792x_config_mac_addr_list(dev); 203 182 204 183 ret = mt7925_init_mlo_caps(&dev->phy); 205 184 if (ret) { ··· 248 225 spin_lock_init(&dev->pm.wake.lock); 249 226 mutex_init(&dev->pm.mutex); 250 227 init_waitqueue_head(&dev->pm.wait); 228 + init_waitqueue_head(&dev->wait); 251 229 spin_lock_init(&dev->pm.txq_lock); 252 230 INIT_DELAYED_WORK(&dev->mphy.mac_work, mt792x_mac_work); 253 231 INIT_DELAYED_WORK(&dev->phy.scan_work, mt7925_scan_work);
+10 -18
drivers/net/wireless/mediatek/mt76/mt7925/mac.c
··· 49 49 break; 50 50 mlink = list_first_entry(&sta_poll_list, 51 51 struct mt792x_link_sta, wcid.poll_list); 52 - msta = container_of(mlink, struct mt792x_sta, deflink); 52 + msta = mlink->sta; 53 53 spin_lock_bh(&dev->mt76.sta_poll_lock); 54 54 list_del_init(&mlink->wcid.poll_list); 55 55 spin_unlock_bh(&dev->mt76.sta_poll_lock); ··· 395 395 396 396 if (status->wcid) { 397 397 mlink = container_of(status->wcid, struct mt792x_link_sta, wcid); 398 - spin_lock_bh(&dev->mt76.sta_poll_lock); 399 - if (list_empty(&mlink->wcid.poll_list)) 400 - list_add_tail(&mlink->wcid.poll_list, 401 - &dev->mt76.sta_poll_list); 402 - spin_unlock_bh(&dev->mt76.sta_poll_lock); 398 + mt76_wcid_add_poll(&dev->mt76, &mlink->wcid); 403 399 } 404 400 405 401 mt792x_get_status_freq_info(status, chfreq); ··· 730 734 u8 p_fmt, q_idx, omac_idx = 0, wmm_idx = 0, band_idx = 0; 731 735 u32 val, sz_txd = mt76_is_mmio(dev) ? MT_TXD_SIZE : MT_SDIO_TXD_SIZE; 732 736 bool is_8023 = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP; 733 - struct mt76_vif *mvif; 737 + struct mt76_vif_link *mvif; 734 738 bool beacon = !!(changed & (BSS_CHANGED_BEACON | 735 739 BSS_CHANGED_BEACON_ENABLED)); 736 740 bool inband_disc = !!(changed & (BSS_CHANGED_UNSOL_BCAST_PROBE_RESP | ··· 739 743 740 744 mconf = vif ? mt792x_vif_to_link((struct mt792x_vif *)vif->drv_priv, 741 745 wcid->link_id) : NULL; 742 - mvif = mconf ? (struct mt76_vif *)&mconf->mt76 : NULL; 746 + mvif = mconf ? (struct mt76_vif_link *)&mconf->mt76 : NULL; 743 747 744 748 if (mvif) { 745 749 omac_idx = mvif->omac_idx; ··· 1050 1054 if (!wcid->sta) 1051 1055 goto out; 1052 1056 1053 - spin_lock_bh(&dev->mt76.sta_poll_lock); 1054 - if (list_empty(&mlink->wcid.poll_list)) 1055 - list_add_tail(&mlink->wcid.poll_list, &dev->mt76.sta_poll_list); 1056 - spin_unlock_bh(&dev->mt76.sta_poll_lock); 1057 + mt76_wcid_add_poll(&dev->mt76, &mlink->wcid); 1057 1058 1058 1059 out: 1059 1060 rcu_read_unlock(); ··· 1128 1135 continue; 1129 1136 1130 1137 mlink = container_of(wcid, struct mt792x_link_sta, wcid); 1131 - spin_lock_bh(&mdev->sta_poll_lock); 1132 - if (list_empty(&mlink->wcid.poll_list)) 1133 - list_add_tail(&mlink->wcid.poll_list, 1134 - &mdev->sta_poll_list); 1135 - spin_unlock_bh(&mdev->sta_poll_lock); 1138 + mt76_wcid_add_poll(&dev->mt76, &mlink->wcid); 1136 1139 continue; 1137 1140 } 1138 1141 ··· 1260 1271 struct mt792x_dev *dev = mvif->phy->dev; 1261 1272 struct ieee80211_hw *hw = mt76_hw(dev); 1262 1273 struct ieee80211_bss_conf *bss_conf; 1274 + struct mt792x_bss_conf *mconf; 1263 1275 int i; 1264 1276 1265 1277 if (vif->type == NL80211_IFTYPE_STATION) ··· 1268 1278 1269 1279 for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) { 1270 1280 bss_conf = mt792x_vif_to_bss_conf(vif, i); 1281 + mconf = mt792x_vif_to_link(mvif, i); 1271 1282 1272 - mt76_connac_mcu_uni_add_dev(&dev->mphy, bss_conf, 1283 + mt76_connac_mcu_uni_add_dev(&dev->mphy, bss_conf, &mconf->mt76, 1273 1284 &mvif->sta.deflink.wcid, true); 1274 1285 mt7925_mcu_set_tx(dev, bss_conf); 1275 1286 } ··· 1300 1309 cancel_delayed_work_sync(&dev->mphy.mac_work); 1301 1310 cancel_delayed_work_sync(&pm->ps_work); 1302 1311 cancel_work_sync(&pm->wake_work); 1312 + dev->sar_inited = false; 1303 1313 1304 1314 for (i = 0; i < 10; i++) { 1305 1315 mutex_lock(&dev->mt76.mutex);
+89 -41
drivers/net/wireless/mediatek/mt76/mt7925/main.c
··· 130 130 131 131 if (he_cap_elem->phy_cap_info[6] & 132 132 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 133 - mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss); 133 + mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss, band); 134 134 } else { 135 135 he_cap_elem->phy_cap_info[9] |= 136 136 u8_encode_bits(IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US, ··· 310 310 int __mt7925_start(struct mt792x_phy *phy) 311 311 { 312 312 struct mt76_phy *mphy = phy->mt76; 313 + struct mt792x_dev *dev = phy->dev; 313 314 int err; 314 315 315 316 err = mt7925_mcu_set_channel_domain(mphy); ··· 321 320 if (err) 322 321 return err; 323 322 324 - err = mt7925_set_tx_sar_pwr(mphy->hw, NULL); 325 - if (err) 326 - return err; 323 + if (!dev->sar_inited) { 324 + err = mt7925_set_tx_sar_pwr(mphy->hw, NULL); 325 + if (err) 326 + return err; 327 + dev->sar_inited = true; 328 + } 327 329 328 330 mt792x_mac_reset_counters(phy); 329 331 set_bit(MT76_STATE_RUNNING, &mphy->state); ··· 369 365 mconf->mt76.omac_idx = ieee80211_vif_is_mld(vif) ? 370 366 0 : mconf->mt76.idx; 371 367 mconf->mt76.band_idx = 0xff; 372 - mconf->mt76.wmm_idx = mconf->mt76.idx % MT76_CONNAC_MAX_WMM_SETS; 368 + mconf->mt76.wmm_idx = ieee80211_vif_is_mld(vif) ? 369 + 0 : mconf->mt76.idx % MT76_CONNAC_MAX_WMM_SETS; 373 370 374 371 if (mvif->phy->mt76->chandef.chan->band != NL80211_BAND_2GHZ) 375 372 mconf->mt76.basic_rates_idx = MT792x_BASIC_RATES_TBL + 4; 376 373 else 377 374 mconf->mt76.basic_rates_idx = MT792x_BASIC_RATES_TBL; 378 375 379 - ret = mt76_connac_mcu_uni_add_dev(&dev->mphy, link_conf, 380 - &mlink->wcid, true); 381 - if (ret) 382 - goto out; 383 - 384 376 dev->mt76.vif_mask |= BIT_ULL(mconf->mt76.idx); 385 377 mvif->phy->omac_mask |= BIT_ULL(mconf->mt76.omac_idx); 386 378 387 379 idx = MT792x_WTBL_RESERVED - mconf->mt76.idx; 388 380 389 - INIT_LIST_HEAD(&mlink->wcid.poll_list); 390 381 mlink->wcid.idx = idx; 391 - mlink->wcid.phy_idx = mconf->mt76.band_idx; 392 - mlink->wcid.hw_key_idx = -1; 393 382 mlink->wcid.tx_info |= MT_WCID_TX_INFO_SET; 394 - mt76_wcid_init(&mlink->wcid); 383 + mt76_wcid_init(&mlink->wcid, 0); 395 384 396 385 mt7925_mac_wtbl_update(dev, idx, 397 386 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); ··· 392 395 ewma_rssi_init(&mconf->rssi); 393 396 394 397 rcu_assign_pointer(dev->mt76.wcid[idx], &mlink->wcid); 398 + 399 + ret = mt76_connac_mcu_uni_add_dev(&dev->mphy, link_conf, &mconf->mt76, 400 + &mlink->wcid, true); 401 + if (ret) 402 + goto out; 403 + 395 404 if (vif->txq) { 396 405 mtxq = (struct mt76_txq *)vif->txq->drv_priv; 397 406 mtxq->wcid = idx; ··· 804 801 mt7925_get_rates_table(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 805 802 bool beacon, bool mcast) 806 803 { 807 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 804 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 808 805 struct mt76_phy *mphy = hw->priv; 809 806 u16 rate; 810 807 u8 i, idx, ht; 811 808 812 - rate = mt76_connac2_mac_tx_rate_val(mphy, vif, beacon, mcast); 809 + rate = mt76_connac2_mac_tx_rate_val(mphy, &vif->bss_conf, beacon, mcast); 813 810 ht = FIELD_GET(MT_TX_RATE_MODE, rate) > MT_PHY_TYPE_OFDM; 814 811 815 812 if (beacon && ht) { ··· 840 837 u8 link_id = link_sta->link_id; 841 838 struct mt792x_link_sta *mlink; 842 839 struct mt792x_sta *msta; 840 + struct mt76_wcid *wcid; 843 841 int ret, idx; 844 842 845 843 msta = (struct mt792x_sta *)link_sta->sta->drv_priv; ··· 851 847 return -ENOSPC; 852 848 853 849 mconf = mt792x_vif_to_link(mvif, link_id); 854 - INIT_LIST_HEAD(&mlink->wcid.poll_list); 850 + mt76_wcid_init(&mlink->wcid, 0); 855 851 mlink->wcid.sta = 1; 856 852 mlink->wcid.idx = idx; 857 - mlink->wcid.phy_idx = mconf->mt76.band_idx; 858 853 mlink->wcid.tx_info |= MT_WCID_TX_INFO_SET; 859 854 mlink->last_txs = jiffies; 860 855 mlink->wcid.link_id = link_sta->link_id; 861 856 mlink->wcid.link_valid = !!link_sta->sta->valid_links; 857 + mlink->sta = msta; 858 + 859 + wcid = &mlink->wcid; 860 + ewma_signal_init(&wcid->rssi); 861 + rcu_assign_pointer(dev->mt76.wcid[wcid->idx], wcid); 862 + mt76_wcid_init(wcid, 0); 863 + ewma_avg_signal_init(&mlink->avg_ack_signal); 864 + memset(mlink->airtime_ac, 0, 865 + sizeof(msta->deflink.airtime_ac)); 862 866 863 867 ret = mt76_connac_pm_wake(&dev->mphy, &dev->pm); 864 868 if (ret) ··· 878 866 link_conf = mt792x_vif_to_bss_conf(vif, link_id); 879 867 880 868 /* should update bss info before STA add */ 881 - if (vif->type == NL80211_IFTYPE_STATION && !link_sta->sta->tdls) 882 - mt7925_mcu_add_bss_info(&dev->phy, mconf->mt76.ctx, 883 - link_conf, link_sta, false); 869 + if (vif->type == NL80211_IFTYPE_STATION && !link_sta->sta->tdls) { 870 + if (ieee80211_vif_is_mld(vif)) 871 + mt7925_mcu_add_bss_info(&dev->phy, mconf->mt76.ctx, 872 + link_conf, link_sta, link_sta != mlink->pri_link); 873 + else 874 + mt7925_mcu_add_bss_info(&dev->phy, mconf->mt76.ctx, 875 + link_conf, link_sta, false); 876 + } 884 877 885 878 if (ieee80211_vif_is_mld(vif) && 886 879 link_sta == mlink->pri_link) { ··· 921 904 struct ieee80211_sta *sta, unsigned long new_links) 922 905 { 923 906 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; 924 - struct mt76_wcid *wcid; 925 907 unsigned int link_id; 926 908 int err = 0; 927 909 ··· 937 921 err = -ENOMEM; 938 922 break; 939 923 } 940 - 941 - wcid = &mlink->wcid; 942 - ewma_signal_init(&wcid->rssi); 943 - rcu_assign_pointer(dev->mt76.wcid[wcid->idx], wcid); 944 - mt76_wcid_init(wcid); 945 - ewma_avg_signal_init(&mlink->avg_ack_signal); 946 - memset(mlink->airtime_ac, 0, 947 - sizeof(msta->deflink.airtime_ac)); 948 924 } 949 925 950 926 msta->valid_links |= BIT(link_id); ··· 1149 1141 struct mt792x_bss_conf *mconf; 1150 1142 1151 1143 mconf = mt792x_link_conf_to_mconf(link_conf); 1152 - mt7925_mcu_add_bss_info(&dev->phy, mconf->mt76.ctx, link_conf, 1153 - link_sta, false); 1144 + mt792x_mac_link_bss_remove(dev, mconf, mlink); 1154 1145 } 1155 1146 1156 1147 spin_lock_bh(&mdev->sta_poll_lock); ··· 1192 1185 if (link_sta != mlink->pri_link) { 1193 1186 mt76_wcid_cleanup(mdev, wcid); 1194 1187 mt76_wcid_mask_clear(mdev->wcid_mask, wcid->idx); 1195 - mt76_wcid_mask_clear(mdev->wcid_phy_mask, wcid->idx); 1196 1188 } 1197 1189 1198 1190 if (msta->deflink_id == link_id) ··· 1206 1200 { 1207 1201 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); 1208 1202 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; 1203 + struct { 1204 + struct { 1205 + u8 omac_idx; 1206 + u8 band_idx; 1207 + __le16 pad; 1208 + } __packed hdr; 1209 + struct req_tlv { 1210 + __le16 tag; 1211 + __le16 len; 1212 + u8 active; 1213 + u8 link_idx; /* hw link idx */ 1214 + u8 omac_addr[ETH_ALEN]; 1215 + } __packed tlv; 1216 + } dev_req = { 1217 + .hdr = { 1218 + .omac_idx = 0, 1219 + .band_idx = 0, 1220 + }, 1221 + .tlv = { 1222 + .tag = cpu_to_le16(DEV_INFO_ACTIVE), 1223 + .len = cpu_to_le16(sizeof(struct req_tlv)), 1224 + .active = true, 1225 + }, 1226 + }; 1209 1227 unsigned long rem; 1210 1228 1211 1229 rem = ieee80211_vif_is_mld(vif) ? msta->valid_links : BIT(0); 1212 1230 1213 1231 mt7925_mac_sta_remove_links(dev, vif, sta, rem); 1232 + 1233 + if (ieee80211_vif_is_mld(vif)) { 1234 + mt7925_mcu_set_dbdc(&dev->mphy, false); 1235 + 1236 + /* recovery omac address for the legacy interface */ 1237 + memcpy(dev_req.tlv.omac_addr, vif->addr, ETH_ALEN); 1238 + mt76_mcu_send_msg(mdev, MCU_UNI_CMD(DEV_INFO_UPDATE), 1239 + &dev_req, sizeof(dev_req), true); 1240 + } 1214 1241 1215 1242 if (vif->type == NL80211_IFTYPE_STATION) { 1216 1243 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; ··· 1289 1250 case IEEE80211_AMPDU_RX_START: 1290 1251 mt76_rx_aggr_start(&dev->mt76, &msta->deflink.wcid, tid, ssn, 1291 1252 params->buf_size); 1292 - mt7925_mcu_uni_rx_ba(dev, params, true); 1253 + mt7925_mcu_uni_rx_ba(dev, vif, params, true); 1293 1254 break; 1294 1255 case IEEE80211_AMPDU_RX_STOP: 1295 1256 mt76_rx_aggr_stop(&dev->mt76, &msta->deflink.wcid, tid); 1296 - mt7925_mcu_uni_rx_ba(dev, params, false); 1257 + mt7925_mcu_uni_rx_ba(dev, vif, params, false); 1297 1258 break; 1298 1259 case IEEE80211_AMPDU_TX_OPERATIONAL: 1299 1260 mtxq->aggr = true; 1300 1261 mtxq->send_bar = false; 1301 - mt7925_mcu_uni_tx_ba(dev, params, true); 1262 + mt7925_mcu_uni_tx_ba(dev, vif, params, true); 1302 1263 break; 1303 1264 case IEEE80211_AMPDU_TX_STOP_FLUSH: 1304 1265 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 1305 1266 mtxq->aggr = false; 1306 1267 clear_bit(tid, &msta->deflink.wcid.ampdu_state); 1307 - mt7925_mcu_uni_tx_ba(dev, params, false); 1268 + mt7925_mcu_uni_tx_ba(dev, vif, params, false); 1308 1269 break; 1309 1270 case IEEE80211_AMPDU_TX_START: 1310 1271 set_bit(tid, &msta->deflink.wcid.ampdu_state); ··· 1313 1274 case IEEE80211_AMPDU_TX_STOP_CONT: 1314 1275 mtxq->aggr = false; 1315 1276 clear_bit(tid, &msta->deflink.wcid.ampdu_state); 1316 - mt7925_mcu_uni_tx_ba(dev, params, false); 1277 + mt7925_mcu_uni_tx_ba(dev, vif, params, false); 1317 1278 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); 1318 1279 break; 1319 1280 } ··· 1934 1895 if (changed & (BSS_CHANGED_QOS | BSS_CHANGED_BEACON_ENABLED)) 1935 1896 mt7925_mcu_set_tx(dev, info); 1936 1897 1898 + if (changed & BSS_CHANGED_BSSID) { 1899 + if (ieee80211_vif_is_mld(vif) && 1900 + hweight16(mvif->valid_links) == 2) 1901 + /* Indicate the secondary setup done */ 1902 + mt7925_mcu_uni_bss_bcnft(dev, info, true); 1903 + } 1904 + 1937 1905 mt792x_mutex_release(dev); 1938 1906 } 1939 1907 ··· 1992 1946 GFP_KERNEL); 1993 1947 mlink = devm_kzalloc(dev->mt76.dev, sizeof(*mlink), 1994 1948 GFP_KERNEL); 1949 + if (!mconf || !mlink) 1950 + return -ENOMEM; 1995 1951 } 1996 1952 1997 1953 mconfs[link_id] = mconf; ··· 2022 1974 goto free; 2023 1975 2024 1976 if (mconf != &mvif->bss_conf) { 1977 + mt7925_mcu_set_bss_pm(dev, link_conf, true); 1978 + 2025 1979 err = mt7925_set_mlo_roc(phy, &mvif->bss_conf, 2026 1980 vif->active_links); 2027 1981 if (err < 0) ··· 2121 2071 struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv; 2122 2072 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 2123 2073 struct mt792x_dev *dev = mt792x_hw_dev(hw); 2124 - struct ieee80211_bss_conf *pri_link_conf; 2125 2074 struct mt792x_bss_conf *mconf; 2126 2075 2127 2076 mutex_lock(&dev->mt76.mutex); 2128 2077 2129 2078 if (ieee80211_vif_is_mld(vif)) { 2130 2079 mconf = mt792x_vif_to_link(mvif, link_conf->link_id); 2131 - pri_link_conf = mt792x_vif_to_bss_conf(vif, mvif->deflink_id); 2132 2080 2133 2081 if (vif->type == NL80211_IFTYPE_STATION && 2134 2082 mconf == &mvif->bss_conf) 2135 - mt7925_mcu_add_bss_info(&dev->phy, NULL, pri_link_conf, 2083 + mt7925_mcu_add_bss_info(&dev->phy, NULL, link_conf, 2136 2084 NULL, false); 2137 2085 } else { 2138 2086 mconf = &mvif->bss_conf;
+160 -76
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
··· 39 39 } else if (cmd == MCU_UNI_CMD(DEV_INFO_UPDATE) || 40 40 cmd == MCU_UNI_CMD(BSS_INFO_UPDATE) || 41 41 cmd == MCU_UNI_CMD(STA_REC_UPDATE) || 42 - cmd == MCU_UNI_CMD(HIF_CTRL) || 43 42 cmd == MCU_UNI_CMD(OFFLOAD) || 44 43 cmd == MCU_UNI_CMD(SUSPEND)) { 45 44 struct mt7925_mcu_uni_event *event; ··· 122 123 int mt7925_mcu_update_arp_filter(struct mt76_dev *dev, 123 124 struct ieee80211_bss_conf *link_conf) 124 125 { 125 - struct ieee80211_vif *mvif = container_of((void *)link_conf->vif, 126 - struct ieee80211_vif, 127 - drv_priv); 128 126 struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); 127 + struct ieee80211_vif *mvif = link_conf->vif; 129 128 struct sk_buff *skb; 130 129 int i, len = min_t(int, mvif->cfg.arp_addr_cnt, 131 130 IEEE80211_BSS_ARP_ADDR_LIST_LEN); ··· 163 166 mt7925_connac_mcu_set_wow_ctrl(struct mt76_phy *phy, struct ieee80211_vif *vif, 164 167 bool suspend, struct cfg80211_wowlan *wowlan) 165 168 { 166 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 169 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 167 170 struct mt76_dev *dev = phy->dev; 168 171 struct { 169 172 struct { ··· 218 221 u8 index, bool enable, 219 222 struct cfg80211_pkt_pattern *pattern) 220 223 { 221 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 224 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 222 225 struct mt7925_wow_pattern_tlv *tlv; 223 226 struct sk_buff *skb; 224 227 struct { ··· 273 276 mt7925_mcu_connection_loss_iter(void *priv, u8 *mac, 274 277 struct ieee80211_vif *vif) 275 278 { 276 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 279 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 277 280 struct mt7925_uni_beacon_loss_event *event = priv; 278 281 279 282 if (mvif->idx != event->hdr.bss_idx) ··· 303 306 static void 304 307 mt7925_mcu_roc_iter(void *priv, u8 *mac, struct ieee80211_vif *vif) 305 308 { 306 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 309 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 307 310 struct mt7925_roc_grant_tlv *grant = priv; 308 311 309 312 if (ieee80211_vif_is_mld(vif) && vif->type == NL80211_IFTYPE_STATION) ··· 338 341 duration = le32_to_cpu(grant->max_interval); 339 342 mod_timer(&dev->phy.roc_timer, 340 343 jiffies + msecs_to_jiffies(duration)); 344 + } 345 + 346 + static void 347 + mt7925_mcu_handle_hif_ctrl_basic(struct mt792x_dev *dev, struct tlv *tlv) 348 + { 349 + struct mt7925_mcu_hif_ctrl_basic_tlv *basic; 350 + 351 + basic = (struct mt7925_mcu_hif_ctrl_basic_tlv *)tlv; 352 + 353 + if (basic->hifsuspend) { 354 + if (basic->hif_tx_traffic_status == HIF_TRAFFIC_IDLE && 355 + basic->hif_rx_traffic_status == HIF_TRAFFIC_IDLE) 356 + /* success */ 357 + dev->hif_idle = true; 358 + else 359 + /* busy */ 360 + /* invalid */ 361 + dev->hif_idle = false; 362 + } else { 363 + dev->hif_resumed = true; 364 + } 365 + wake_up(&dev->wait); 366 + } 367 + 368 + static void 369 + mt7925_mcu_uni_hif_ctrl_event(struct mt792x_dev *dev, struct sk_buff *skb) 370 + { 371 + struct tlv *tlv; 372 + u32 tlv_len; 373 + 374 + skb_pull(skb, sizeof(struct mt7925_mcu_rxd) + 4); 375 + tlv = (struct tlv *)skb->data; 376 + tlv_len = skb->len; 377 + 378 + while (tlv_len > 0 && le16_to_cpu(tlv->len) <= tlv_len) { 379 + switch (le16_to_cpu(tlv->tag)) { 380 + case UNI_EVENT_HIF_CTRL_BASIC: 381 + mt7925_mcu_handle_hif_ctrl_basic(dev, tlv); 382 + break; 383 + default: 384 + break; 385 + } 386 + tlv_len -= le16_to_cpu(tlv->len); 387 + tlv = (struct tlv *)((char *)(tlv) + le16_to_cpu(tlv->len)); 388 + } 341 389 } 342 390 343 391 static void ··· 430 388 struct mt7925_mcu_txs_event { 431 389 u8 ver; 432 390 u8 rsv[3]; 433 - u8 data[0]; 391 + u8 data[]; 434 392 } __packed * txs; 435 393 struct tlv *tlv; 436 394 u32 tlv_len; ··· 531 489 rxd = (struct mt7925_mcu_rxd *)skb->data; 532 490 533 491 switch (rxd->eid) { 492 + case MCU_UNI_EVENT_HIF_CTRL: 493 + mt7925_mcu_uni_hif_ctrl_event(dev, skb); 494 + break; 534 495 case MCU_UNI_EVENT_FW_LOG_2_HOST: 535 496 mt7925_mcu_uni_debug_msg_event(dev, skb); 536 497 break; ··· 575 530 } 576 531 577 532 static int 578 - mt7925_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif *mvif, 533 + mt7925_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif_link *mvif, 534 + struct mt76_wcid *wcid, 579 535 struct ieee80211_ampdu_params *params, 580 536 bool enable, bool tx) 581 537 { 582 - struct mt76_wcid *wcid = (struct mt76_wcid *)params->sta->drv_priv; 583 538 struct sta_rec_ba_uni *ba; 584 539 struct sk_buff *skb; 585 540 struct tlv *tlv; ··· 607 562 608 563 /** starec & wtbl **/ 609 564 int mt7925_mcu_uni_tx_ba(struct mt792x_dev *dev, 565 + struct ieee80211_vif *vif, 610 566 struct ieee80211_ampdu_params *params, 611 567 bool enable) 612 568 { 613 569 struct mt792x_sta *msta = (struct mt792x_sta *)params->sta->drv_priv; 614 - struct mt792x_vif *mvif = msta->vif; 570 + struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 571 + struct mt792x_link_sta *mlink; 572 + struct mt792x_bss_conf *mconf; 573 + unsigned long usable_links = ieee80211_vif_usable_links(vif); 574 + struct mt76_wcid *wcid; 575 + u8 link_id, ret; 615 576 616 - if (enable && !params->amsdu) 617 - msta->deflink.wcid.amsdu = false; 577 + for_each_set_bit(link_id, &usable_links, IEEE80211_MLD_MAX_NUM_LINKS) { 578 + mconf = mt792x_vif_to_link(mvif, link_id); 579 + mlink = mt792x_sta_to_link(msta, link_id); 580 + wcid = &mlink->wcid; 618 581 619 - return mt7925_mcu_sta_ba(&dev->mt76, &mvif->bss_conf.mt76, params, 620 - enable, true); 582 + if (enable && !params->amsdu) 583 + mlink->wcid.amsdu = false; 584 + 585 + ret = mt7925_mcu_sta_ba(&dev->mt76, &mconf->mt76, wcid, params, 586 + enable, true); 587 + if (ret < 0) 588 + break; 589 + } 590 + 591 + return ret; 621 592 } 622 593 623 594 int mt7925_mcu_uni_rx_ba(struct mt792x_dev *dev, 595 + struct ieee80211_vif *vif, 624 596 struct ieee80211_ampdu_params *params, 625 597 bool enable) 626 598 { 627 599 struct mt792x_sta *msta = (struct mt792x_sta *)params->sta->drv_priv; 628 - struct mt792x_vif *mvif = msta->vif; 600 + struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 601 + struct mt792x_link_sta *mlink; 602 + struct mt792x_bss_conf *mconf; 603 + unsigned long usable_links = ieee80211_vif_usable_links(vif); 604 + struct mt76_wcid *wcid; 605 + u8 link_id, ret; 629 606 630 - return mt7925_mcu_sta_ba(&dev->mt76, &mvif->bss_conf.mt76, params, 631 - enable, false); 607 + for_each_set_bit(link_id, &usable_links, IEEE80211_MLD_MAX_NUM_LINKS) { 608 + mconf = mt792x_vif_to_link(mvif, link_id); 609 + mlink = mt792x_sta_to_link(msta, link_id); 610 + wcid = &mlink->wcid; 611 + 612 + ret = mt7925_mcu_sta_ba(&dev->mt76, &mconf->mt76, wcid, params, 613 + enable, false); 614 + if (ret < 0) 615 + break; 616 + } 617 + 618 + return ret; 632 619 } 633 620 634 621 static int mt7925_load_clc(struct mt792x_dev *dev, const char *fw_name) ··· 715 638 for (offset = 0; offset < len; offset += le32_to_cpu(clc->len)) { 716 639 clc = (const struct mt7925_clc *)(clc_base + offset); 717 640 718 - if (clc->idx > ARRAY_SIZE(phy->clc)) 641 + if (clc->idx >= ARRAY_SIZE(phy->clc)) 719 642 break; 720 643 721 644 /* do not init buf again if chip reset triggered */ ··· 900 823 mt7925_mcu_parse_phy_cap(dev, tlv->data); 901 824 break; 902 825 case MT_NIC_CAP_CHIP_CAP: 903 - memcpy(&dev->phy.chip_cap, (void *)skb->data, sizeof(u64)); 826 + dev->phy.chip_cap = le64_to_cpu(*(__le64 *)tlv->data); 904 827 break; 905 828 case MT_NIC_CAP_EML_CAP: 906 829 mt7925_mcu_parse_eml_cap(dev, tlv->data); ··· 1230 1153 u8 rsv[4]; 1231 1154 } __packed hdr; 1232 1155 struct roc_acquire_tlv roc[2]; 1233 - } __packed req; 1156 + } __packed req = { 1157 + .roc[0].tag = cpu_to_le16(UNI_ROC_NUM), 1158 + .roc[0].len = cpu_to_le16(sizeof(struct roc_acquire_tlv)), 1159 + .roc[1].tag = cpu_to_le16(UNI_ROC_NUM), 1160 + .roc[1].len = cpu_to_le16(sizeof(struct roc_acquire_tlv)) 1161 + }; 1234 1162 1235 1163 if (!mconf || hweight16(vif->valid_links) < 2 || 1236 1164 hweight16(sel_links) != 2) ··· 1282 1200 req.roc[i].bw_from_ap = CMD_CBW_20MHZ; 1283 1201 req.roc[i].center_chan = center_ch; 1284 1202 req.roc[i].center_chan_from_ap = center_ch; 1203 + req.roc[i].center_chan2 = 0; 1204 + req.roc[i].center_chan2_from_ap = 0; 1285 1205 1286 1206 /* STR : 0xfe indicates BAND_ALL with enabling DBDC 1287 1207 * EMLSR : 0xff indicates (BAND_AUTO) without DBDC ··· 1299 1215 } 1300 1216 1301 1217 return mt76_mcu_send_msg(&mvif->phy->dev->mt76, MCU_UNI_CMD(ROC), 1302 - &req, sizeof(req), false); 1218 + &req, sizeof(req), true); 1303 1219 } 1304 1220 1305 1221 int mt7925_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf, ··· 1348 1264 } 1349 1265 1350 1266 return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(ROC), 1351 - &req, sizeof(req), false); 1267 + &req, sizeof(req), true); 1352 1268 } 1353 1269 1354 1270 int mt7925_mcu_abort_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf, ··· 1378 1294 }; 1379 1295 1380 1296 return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(ROC), 1381 - &req, sizeof(req), false); 1297 + &req, sizeof(req), true); 1382 1298 } 1383 1299 1384 1300 int mt7925_mcu_set_eeprom(struct mt792x_dev *dev) ··· 1441 1357 &ps_req, sizeof(ps_req), true); 1442 1358 } 1443 1359 1444 - static int 1360 + int 1445 1361 mt7925_mcu_uni_bss_bcnft(struct mt792x_dev *dev, 1446 1362 struct ieee80211_bss_conf *link_conf, bool enable) 1447 1363 { ··· 1531 1447 int err; 1532 1448 1533 1449 err = mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(BSS_INFO_UPDATE), 1534 - &req1, sizeof(req1), false); 1450 + &req1, sizeof(req1), true); 1535 1451 if (err < 0 || !enable) 1536 1452 return err; 1537 1453 1538 1454 return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(BSS_INFO_UPDATE), 1539 - &req, sizeof(req), false); 1455 + &req, sizeof(req), true); 1540 1456 } 1541 1457 1542 1458 static void ··· 1854 1770 mt7925_mcu_sta_cmd(struct mt76_phy *phy, 1855 1771 struct mt76_sta_cmd_info *info) 1856 1772 { 1857 - struct mt76_vif *mvif = (struct mt76_vif *)info->vif->drv_priv; 1773 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)info->vif->drv_priv; 1858 1774 struct mt76_dev *dev = phy->dev; 1859 1775 struct sk_buff *skb; 1860 1776 int conn_state; ··· 1867 1783 conn_state = info->enable ? CONN_STATE_PORT_SECURE : 1868 1784 CONN_STATE_DISCONNECT; 1869 1785 if (info->link_sta) 1870 - mt76_connac_mcu_sta_basic_tlv(dev, skb, info->vif, 1786 + mt76_connac_mcu_sta_basic_tlv(dev, skb, info->link_conf, 1871 1787 info->link_sta, 1872 1788 conn_state, info->newly); 1873 1789 if (info->link_sta && info->enable) { ··· 1921 1837 return PTR_ERR(skb); 1922 1838 1923 1839 if (info->enable) 1924 - mt76_connac_mcu_sta_basic_tlv(dev, skb, info->vif, 1840 + mt76_connac_mcu_sta_basic_tlv(dev, skb, info->link_conf, 1925 1841 info->link_sta, 1926 1842 info->enable, info->newly); 1927 1843 ··· 1967 1883 struct mt76_sta_cmd_info info = { 1968 1884 .link_sta = link_sta, 1969 1885 .vif = vif, 1886 + .link_conf = &vif->bss_conf, 1970 1887 .enable = enable, 1971 1888 .cmd = MCU_UNI_CMD(STA_REC_UPDATE), 1972 1889 .state = state, ··· 1983 1898 mlink = mt792x_sta_to_link(msta, link_sta->link_id); 1984 1899 } 1985 1900 info.wcid = link_sta ? &mlink->wcid : &mvif->sta.deflink.wcid; 1986 - info.newly = link_sta ? state != MT76_STA_INFO_STATE_ASSOC : true; 1901 + 1902 + if (link_sta) 1903 + info.newly = state != MT76_STA_INFO_STATE_ASSOC; 1904 + else 1905 + info.newly = state == MT76_STA_INFO_STATE_ASSOC ? false : true; 1987 1906 1988 1907 if (ieee80211_vif_is_mld(vif)) 1989 1908 err = mt7925_mcu_mlo_sta_cmd(&dev->mphy, &info); ··· 2003 1914 { 2004 1915 #define MT7925_FIF_BIT_CLR BIT(1) 2005 1916 #define MT7925_FIF_BIT_SET BIT(0) 2006 - struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 2007 - unsigned long valid = ieee80211_vif_is_mld(vif) ? 2008 - mvif->valid_links : BIT(0); 2009 - struct ieee80211_bss_conf *bss_conf; 2010 1917 int err = 0; 2011 - int i; 2012 1918 2013 1919 if (enable) { 2014 - for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) { 2015 - bss_conf = mt792x_vif_to_bss_conf(vif, i); 2016 - err = mt7925_mcu_uni_bss_bcnft(dev, bss_conf, true); 2017 - if (err < 0) 2018 - return err; 2019 - } 1920 + err = mt7925_mcu_uni_bss_bcnft(dev, &vif->bss_conf, true); 1921 + if (err < 0) 1922 + return err; 2020 1923 2021 1924 return mt7925_mcu_set_rxfilter(dev, 0, 2022 1925 MT7925_FIF_BIT_SET, 2023 1926 MT_WF_RFCR_DROP_OTHER_BEACON); 2024 1927 } 2025 1928 2026 - for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) { 2027 - bss_conf = mt792x_vif_to_bss_conf(vif, i); 2028 - err = mt7925_mcu_set_bss_pm(dev, bss_conf, false); 2029 - if (err) 2030 - return err; 2031 - } 1929 + err = mt7925_mcu_set_bss_pm(dev, &vif->bss_conf, false); 1930 + if (err < 0) 1931 + return err; 2032 1932 2033 1933 return mt7925_mcu_set_rxfilter(dev, 0, 2034 1934 MT7925_FIF_BIT_CLR, ··· 2054 1976 int mt7925_mcu_set_sniffer(struct mt792x_dev *dev, struct ieee80211_vif *vif, 2055 1977 bool enable) 2056 1978 { 2057 - struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 2058 - 2059 1979 struct { 2060 1980 struct { 2061 1981 u8 band_idx; ··· 2067 1991 } __packed enable; 2068 1992 } __packed req = { 2069 1993 .hdr = { 2070 - .band_idx = mvif->bss_conf.mt76.band_idx, 1994 + .band_idx = 0, 2071 1995 }, 2072 1996 .enable = { 2073 1997 .tag = cpu_to_le16(UNI_SNIFFER_ENABLE), ··· 2126 2050 } __packed tlv; 2127 2051 } __packed req = { 2128 2052 .hdr = { 2129 - .band_idx = vif->bss_conf.mt76.band_idx, 2053 + .band_idx = 0, 2130 2054 }, 2131 2055 .tlv = { 2132 2056 .tag = cpu_to_le16(UNI_SNIFFER_CONFIG), ··· 2255 2179 req = (struct bss_rlm_tlv *)tlv; 2256 2180 req->control_channel = chandef->chan->hw_value; 2257 2181 req->center_chan = ieee80211_frequency_to_channel(freq1); 2258 - req->center_chan2 = ieee80211_frequency_to_channel(freq2); 2182 + req->center_chan2 = 0; 2259 2183 req->tx_streams = hweight8(phy->antenna_mask); 2260 2184 req->ht_op_info = 4; /* set HT 40M allowed */ 2261 2185 req->rx_streams = hweight8(phy->antenna_mask); 2262 - req->band = band; 2186 + req->center_chan2 = 0; 2187 + req->sco = 0; 2188 + req->band = 1; 2189 + 2190 + switch (band) { 2191 + case NL80211_BAND_2GHZ: 2192 + req->band = 1; 2193 + break; 2194 + case NL80211_BAND_5GHZ: 2195 + req->band = 2; 2196 + break; 2197 + case NL80211_BAND_6GHZ: 2198 + req->band = 3; 2199 + break; 2200 + default: 2201 + break; 2202 + } 2263 2203 2264 2204 switch (chandef->width) { 2265 2205 case NL80211_CHAN_WIDTH_40: ··· 2286 2194 break; 2287 2195 case NL80211_CHAN_WIDTH_80P80: 2288 2196 req->bw = CMD_CBW_8080MHZ; 2197 + req->center_chan2 = ieee80211_frequency_to_channel(freq2); 2289 2198 break; 2290 2199 case NL80211_CHAN_WIDTH_160: 2291 2200 req->bw = CMD_CBW_160MHZ; ··· 2312 2219 } 2313 2220 2314 2221 static struct sk_buff * 2315 - __mt7925_mcu_alloc_bss_req(struct mt76_dev *dev, struct mt76_vif *mvif, int len) 2222 + __mt7925_mcu_alloc_bss_req(struct mt76_dev *dev, struct mt76_vif_link *mvif, int len) 2316 2223 { 2317 2224 struct bss_req_hdr hdr = { 2318 2225 .bss_idx = mvif->idx, ··· 2328 2235 return skb; 2329 2236 } 2330 2237 2331 - int mt7925_mcu_set_chctx(struct mt76_phy *phy, struct mt76_vif *mvif, 2238 + int mt7925_mcu_set_chctx(struct mt76_phy *phy, struct mt76_vif_link *mvif, 2332 2239 struct ieee80211_bss_conf *link_conf, 2333 2240 struct ieee80211_chanctx_conf *ctx) 2334 2241 { ··· 2481 2388 struct ieee80211_bss_conf *link_conf) 2482 2389 { 2483 2390 struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); 2484 - struct mt76_vif *mvif = &mconf->mt76; 2391 + struct mt76_vif_link *mvif = &mconf->mt76; 2485 2392 struct bss_sec_tlv { 2486 2393 __le16 tag; 2487 2394 __le16 len; ··· 2532 2439 &link_conf->chanreq.oper; 2533 2440 struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); 2534 2441 enum nl80211_band band = chandef->chan->band; 2535 - struct mt76_vif *mvif = &mconf->mt76; 2442 + struct mt76_vif_link *mvif = &mconf->mt76; 2536 2443 struct bss_rate_tlv *bmc; 2537 2444 struct tlv *tlv; 2538 2445 u8 idx = mvif->mcast_rates_idx ? ··· 2556 2463 mt7925_mcu_bss_mld_tlv(struct sk_buff *skb, 2557 2464 struct ieee80211_bss_conf *link_conf) 2558 2465 { 2466 + struct ieee80211_vif *vif = link_conf->vif; 2559 2467 struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); 2560 2468 struct mt792x_vif *mvif = (struct mt792x_vif *)link_conf->vif->drv_priv; 2561 2469 struct bss_mld_tlv *mld; ··· 2577 2483 mld->eml_enable = !!(link_conf->vif->cfg.eml_cap & 2578 2484 IEEE80211_EML_CAP_EMLSR_SUPP); 2579 2485 2580 - memcpy(mld->mac_addr, link_conf->addr, ETH_ALEN); 2486 + memcpy(mld->mac_addr, vif->addr, ETH_ALEN); 2581 2487 } 2582 2488 2583 2489 static void ··· 2708 2614 MCU_UNI_CMD(BSS_INFO_UPDATE), true); 2709 2615 } 2710 2616 2711 - int mt7925_mcu_set_dbdc(struct mt76_phy *phy) 2617 + int mt7925_mcu_set_dbdc(struct mt76_phy *phy, bool enable) 2712 2618 { 2713 2619 struct mt76_dev *mdev = phy->dev; 2714 2620 ··· 2728 2634 tlv = mt76_connac_mcu_add_tlv(skb, UNI_MBMC_SETTING, sizeof(*conf)); 2729 2635 conf = (struct mbmc_conf_tlv *)tlv; 2730 2636 2731 - conf->mbmc_en = 1; 2637 + conf->mbmc_en = enable; 2732 2638 conf->band = 0; /* unused */ 2733 2639 2734 2640 err = mt76_mcu_skb_send_msg(mdev, skb, MCU_UNI_CMD(SET_DBDC_PARMS), ··· 2737 2643 return err; 2738 2644 } 2739 2645 2740 - #define MT76_CONNAC_SCAN_CHANNEL_TIME 60 2741 - 2742 2646 int mt7925_mcu_hw_scan(struct mt76_phy *phy, struct ieee80211_vif *vif, 2743 2647 struct ieee80211_scan_request *scan_req) 2744 2648 { 2745 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 2649 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 2746 2650 struct cfg80211_scan_request *sreq = &scan_req->req; 2747 - int n_ssids = 0, err, i, duration; 2651 + int n_ssids = 0, err, i; 2748 2652 struct ieee80211_channel **scan_list = sreq->channels; 2749 2653 struct mt76_dev *mdev = phy->dev; 2750 2654 struct mt76_connac_mcu_scan_channel *chan; ··· 2777 2685 req = (struct scan_req_tlv *)tlv; 2778 2686 req->scan_type = sreq->n_ssids ? 1 : 0; 2779 2687 req->probe_req_num = sreq->n_ssids ? 2 : 0; 2780 - 2781 - duration = MT76_CONNAC_SCAN_CHANNEL_TIME; 2782 - /* increase channel time for passive scan */ 2783 - if (!sreq->n_ssids) 2784 - duration *= 2; 2785 - req->timeout_value = cpu_to_le16(sreq->n_channels * duration); 2786 - req->channel_min_dwell_time = cpu_to_le16(duration); 2787 - req->channel_dwell_time = cpu_to_le16(duration); 2788 2688 2789 2689 tlv = mt76_connac_mcu_add_tlv(skb, UNI_SCAN_SSID, sizeof(*ssid)); 2790 2690 ssid = (struct scan_ssid_tlv *)tlv; ··· 2849 2765 struct ieee80211_vif *vif, 2850 2766 struct cfg80211_sched_scan_request *sreq) 2851 2767 { 2852 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 2768 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 2853 2769 struct ieee80211_channel **scan_list = sreq->channels; 2854 2770 struct mt76_connac_mcu_scan_channel *chan; 2855 2771 struct mt76_dev *mdev = phy->dev; ··· 2985 2901 int mt7925_mcu_cancel_hw_scan(struct mt76_phy *phy, 2986 2902 struct ieee80211_vif *vif) 2987 2903 { 2988 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 2904 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 2989 2905 struct { 2990 2906 struct scan_hdr { 2991 2907 u8 seq_num;
+5 -2
drivers/net/wireless/mediatek/mt76/mt7925/mcu.h
··· 616 616 } 617 617 } 618 618 619 - int mt7925_mcu_set_dbdc(struct mt76_phy *phy); 619 + int mt7925_mcu_set_dbdc(struct mt76_phy *phy, bool enable); 620 620 int mt7925_mcu_hw_scan(struct mt76_phy *phy, struct ieee80211_vif *vif, 621 621 struct ieee80211_scan_request *scan_req); 622 622 int mt7925_mcu_cancel_hw_scan(struct mt76_phy *phy, ··· 637 637 int mt7925_mcu_set_deep_sleep(struct mt792x_dev *dev, bool enable); 638 638 int mt7925_mcu_set_channel_domain(struct mt76_phy *phy); 639 639 int mt7925_mcu_set_radio_en(struct mt792x_phy *phy, bool enable); 640 - int mt7925_mcu_set_chctx(struct mt76_phy *phy, struct mt76_vif *mvif, 640 + int mt7925_mcu_set_chctx(struct mt76_phy *phy, struct mt76_vif_link *mvif, 641 641 struct ieee80211_bss_conf *link_conf, 642 642 struct ieee80211_chanctx_conf *ctx); 643 643 int mt7925_mcu_set_rate_txpower(struct mt76_phy *phy); 644 644 int mt7925_mcu_update_arp_filter(struct mt76_dev *dev, 645 645 struct ieee80211_bss_conf *link_conf); 646 + int 647 + mt7925_mcu_uni_bss_bcnft(struct mt792x_dev *dev, 648 + struct ieee80211_bss_conf *link_conf, bool enable); 646 649 #endif
+23
drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
··· 27 27 28 28 #define MCU_UNI_EVENT_ROC 0x27 29 29 30 + #define HIF_TRAFFIC_IDLE 0x2 31 + 32 + enum { 33 + UNI_EVENT_HIF_CTRL_BASIC = 0, 34 + UNI_EVENT_HIF_CTRL_TAG_NUM 35 + }; 36 + 37 + struct mt7925_mcu_hif_ctrl_basic_tlv { 38 + __le16 tag; 39 + __le16 len; 40 + u8 cid; 41 + u8 pad[3]; 42 + u32 status; 43 + u8 hif_type; 44 + u8 hif_tx_traffic_status; 45 + u8 hif_rx_traffic_status; 46 + u8 hifsuspend; 47 + u8 rsv[4]; 48 + } __packed; 49 + 30 50 enum { 31 51 UNI_ROC_ACQUIRE, 32 52 UNI_ROC_ABORT, ··· 235 215 int mt7925_mcu_set_rxfilter(struct mt792x_dev *dev, u32 fif, 236 216 u8 bit_op, u32 bit_map); 237 217 218 + void mt7925_regd_update(struct mt792x_dev *dev); 238 219 int mt7925_mac_init(struct mt792x_dev *dev); 239 220 int mt7925_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, 240 221 struct ieee80211_sta *sta); ··· 263 242 struct ieee80211_vif *vif, 264 243 bool enable); 265 244 int mt7925_mcu_uni_tx_ba(struct mt792x_dev *dev, 245 + struct ieee80211_vif *vif, 266 246 struct ieee80211_ampdu_params *params, 267 247 bool enable); 268 248 int mt7925_mcu_uni_rx_ba(struct mt792x_dev *dev, 249 + struct ieee80211_vif *vif, 269 250 struct ieee80211_ampdu_params *params, 270 251 bool enable); 271 252 void mt7925_scan_work(struct work_struct *work);
+26 -7
drivers/net/wireless/mediatek/mt76/mt7925/pci.c
··· 442 442 struct mt76_dev *mdev = pci_get_drvdata(pdev); 443 443 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); 444 444 struct mt76_connac_pm *pm = &dev->pm; 445 - int i, err; 445 + int i, err, ret; 446 446 447 447 pm->suspended = true; 448 + dev->hif_resumed = false; 448 449 flush_work(&dev->reset_work); 449 450 cancel_delayed_work_sync(&pm->ps_work); 450 451 cancel_work_sync(&pm->wake_work); ··· 456 455 if (err < 0) 457 456 goto restore_suspend; 458 457 458 + wait_event_timeout(dev->wait, 459 + !dev->regd_in_progress, 5 * HZ); 460 + 459 461 /* always enable deep sleep during suspend to reduce 460 462 * power consumption 461 463 */ 462 464 mt7925_mcu_set_deep_sleep(dev, true); 463 465 464 - err = mt76_connac_mcu_set_hif_suspend(mdev, true); 465 - if (err) 466 + mt76_connac_mcu_set_hif_suspend(mdev, true, false); 467 + ret = wait_event_timeout(dev->wait, 468 + dev->hif_idle, 3 * HZ); 469 + if (!ret) { 470 + err = -ETIMEDOUT; 466 471 goto restore_suspend; 472 + } 467 473 468 474 napi_disable(&mdev->tx_napi); 469 475 mt76_worker_disable(&mdev->tx_worker); ··· 514 506 if (!pm->ds_enable) 515 507 mt7925_mcu_set_deep_sleep(dev, false); 516 508 517 - mt76_connac_mcu_set_hif_suspend(mdev, false); 518 - 509 + mt76_connac_mcu_set_hif_suspend(mdev, false, false); 510 + ret = wait_event_timeout(dev->wait, 511 + dev->hif_resumed, 3 * HZ); 512 + if (!ret) 513 + err = -ETIMEDOUT; 519 514 restore_suspend: 520 515 pm->suspended = false; 521 516 ··· 534 523 struct mt76_dev *mdev = pci_get_drvdata(pdev); 535 524 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); 536 525 struct mt76_connac_pm *pm = &dev->pm; 537 - int i, err; 526 + int i, err, ret; 538 527 528 + dev->hif_idle = false; 539 529 err = mt792x_mcu_drv_pmctrl(dev); 540 530 if (err < 0) 541 531 goto failed; ··· 565 553 napi_schedule(&mdev->tx_napi); 566 554 local_bh_enable(); 567 555 568 - err = mt76_connac_mcu_set_hif_suspend(mdev, false); 556 + mt76_connac_mcu_set_hif_suspend(mdev, false, false); 557 + ret = wait_event_timeout(dev->wait, 558 + dev->hif_resumed, 3 * HZ); 559 + if (!ret) { 560 + err = -ETIMEDOUT; 561 + goto failed; 562 + } 569 563 570 564 /* restore previous ds setting */ 571 565 if (!pm->ds_enable) 572 566 mt7925_mcu_set_deep_sleep(dev, false); 573 567 568 + mt7925_regd_update(dev); 574 569 failed: 575 570 pm->suspended = false; 576 571
+15 -5
drivers/net/wireless/mediatek/mt76/mt7925/usb.c
··· 243 243 { 244 244 struct mt792x_dev *dev = usb_get_intfdata(intf); 245 245 struct mt76_connac_pm *pm = &dev->pm; 246 - int err; 246 + int err, ret; 247 247 248 248 pm->suspended = true; 249 + dev->hif_resumed = false; 249 250 flush_work(&dev->reset_work); 250 251 251 - err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, true); 252 - if (err) 252 + mt76_connac_mcu_set_hif_suspend(&dev->mt76, true, false); 253 + ret = wait_event_timeout(dev->wait, 254 + dev->hif_idle, 3 * HZ); 255 + if (!ret) { 256 + err = -ETIMEDOUT; 253 257 goto failed; 258 + } 254 259 255 260 mt76u_stop_rx(&dev->mt76); 256 261 mt76u_stop_tx(&dev->mt76); ··· 276 271 struct mt792x_dev *dev = usb_get_intfdata(intf); 277 272 struct mt76_connac_pm *pm = &dev->pm; 278 273 bool reinit = true; 279 - int err, i; 274 + int err, i, ret; 280 275 276 + dev->hif_idle = false; 281 277 for (i = 0; i < 10; i++) { 282 278 u32 val = mt76_rr(dev, MT_WF_SW_DEF_CR_USB_MCU_EVENT); 283 279 ··· 304 298 if (err < 0) 305 299 goto failed; 306 300 307 - err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, false); 301 + mt76_connac_mcu_set_hif_suspend(&dev->mt76, false, false); 302 + ret = wait_event_timeout(dev->wait, 303 + dev->hif_resumed, 3 * HZ); 304 + if (!ret) 305 + err = -ETIMEDOUT; 308 306 failed: 309 307 pm->suspended = false; 310 308
+20 -3
drivers/net/wireless/mediatek/mt76/mt792x.h
··· 28 28 #define MT792x_CHIP_CAP_CLC_EVT_EN BIT(0) 29 29 #define MT792x_CHIP_CAP_RSSI_NOTIFY_EVT_EN BIT(1) 30 30 #define MT792x_CHIP_CAP_MLO_EVT_EN BIT(2) 31 + #define MT792x_CHIP_CAP_WF_RF_PIN_CTRL_EVT_EN BIT(3) 31 32 32 33 /* NOTE: used to map mt76_rates. idx may change if firmware expands table */ 33 34 #define MT792x_BASIC_RATES_TBL 11 ··· 117 116 }; 118 117 119 118 struct mt792x_bss_conf { 120 - struct mt76_vif mt76; /* must be first */ 119 + struct mt76_vif_link mt76; /* must be first */ 121 120 struct mt792x_vif *vif; 122 121 struct ewma_rssi rssi; 123 122 struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS]; ··· 134 133 struct mt792x_phy *phy; 135 134 u16 valid_links; 136 135 u8 deflink_id; 136 + 137 + struct work_struct csa_work; 138 + struct timer_list csa_timer; 137 139 }; 138 140 139 141 struct mt792x_phy { ··· 210 206 struct mt76_phy mphy; 211 207 }; 212 208 209 + struct mac_address macaddr_list[8]; 210 + 213 211 const struct mt76_bus_ops *bus_ops; 214 212 struct mt792x_phy phy; 215 213 ··· 222 216 bool has_eht:1; 223 217 bool regd_in_progress:1; 224 218 bool aspm_supported:1; 219 + bool hif_idle:1; 220 + bool hif_resumed:1; 221 + bool sar_inited:1; 222 + bool regd_change:1; 225 223 wait_queue_head_t wait; 226 224 227 225 struct work_struct init_work; ··· 245 235 enum environment_cap country_ie_env; 246 236 u32 backup_l1; 247 237 u32 backup_l2; 238 + 239 + struct ieee80211_chanctx_conf *new_ctx; 248 240 }; 249 241 250 242 static inline struct mt792x_bss_conf * 251 243 mt792x_vif_to_link(struct mt792x_vif *mvif, u8 link_id) 252 244 { 253 245 struct ieee80211_vif *vif; 246 + struct mt792x_bss_conf *bss_conf; 254 247 255 248 vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv); 256 249 ··· 261 248 link_id >= IEEE80211_LINK_UNSPECIFIED) 262 249 return &mvif->bss_conf; 263 250 264 - return rcu_dereference_protected(mvif->link_conf[link_id], 265 - lockdep_is_held(&mvif->phy->dev->mt76.mutex)); 251 + bss_conf = rcu_dereference_protected(mvif->link_conf[link_id], 252 + lockdep_is_held(&mvif->phy->dev->mt76.mutex)); 253 + 254 + return bss_conf ? bss_conf : &mvif->bss_conf; 266 255 } 267 256 268 257 static inline struct mt792x_link_sta * ··· 379 364 u64 timestamp); 380 365 void mt792x_tx_worker(struct mt76_worker *w); 381 366 void mt792x_roc_timer(struct timer_list *timer); 367 + void mt792x_csa_timer(struct timer_list *timer); 382 368 void mt792x_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 383 369 u32 queues, bool drop); 384 370 int mt792x_assign_vif_chanctx(struct ieee80211_hw *hw, ··· 430 414 void mt792x_mac_link_bss_remove(struct mt792x_dev *dev, 431 415 struct mt792x_bss_conf *mconf, 432 416 struct mt792x_link_sta *mlink); 417 + void mt792x_config_mac_addr_list(struct mt792x_dev *dev); 433 418 434 419 static inline char *mt792x_ram_name(struct mt792x_dev *dev) 435 420 {
+45 -3
drivers/net/wireless/mediatek/mt76/mt792x_core.c
··· 38 38 .max = 1, 39 39 .types = BIT(NL80211_IFTYPE_AP) | 40 40 BIT(NL80211_IFTYPE_P2P_GO) 41 + }, 42 + { 43 + .max = 1, 44 + .types = BIT(NL80211_IFTYPE_P2P_DEVICE) 41 45 } 42 46 }; 43 47 ··· 49 45 { 50 46 .limits = if_limits_chanctx, 51 47 .n_limits = ARRAY_SIZE(if_limits_chanctx), 52 - .max_interfaces = 2, 48 + .max_interfaces = 3, 53 49 .num_different_channels = 2, 54 50 .beacon_int_infra_match = false, 55 51 } ··· 151 147 link_conf = mt792x_vif_to_bss_conf(vif, mconf->link_id); 152 148 153 149 mt76_connac_free_pending_tx_skbs(&dev->pm, &mlink->wcid); 154 - mt76_connac_mcu_uni_add_dev(&dev->mphy, link_conf, &mlink->wcid, false); 150 + mt76_connac_mcu_uni_add_dev(&dev->mphy, link_conf, &mconf->mt76, 151 + &mlink->wcid, false); 155 152 156 153 rcu_assign_pointer(dev->mt76.wcid[idx], NULL); 157 154 ··· 289 284 } 290 285 EXPORT_SYMBOL_GPL(mt792x_roc_timer); 291 286 287 + void mt792x_csa_timer(struct timer_list *timer) 288 + { 289 + struct mt792x_vif *mvif = from_timer(mvif, timer, csa_timer); 290 + 291 + ieee80211_queue_work(mvif->phy->mt76->hw, &mvif->csa_work); 292 + } 293 + EXPORT_SYMBOL_GPL(mt792x_csa_timer); 294 + 292 295 void mt792x_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 293 296 u32 queues, bool drop) 294 297 { ··· 338 325 mctx->bss_conf = NULL; 339 326 mvif->bss_conf.mt76.ctx = NULL; 340 327 mutex_unlock(&dev->mt76.mutex); 328 + 329 + if (vif->bss_conf.csa_active) { 330 + del_timer_sync(&mvif->csa_timer); 331 + cancel_work_sync(&mvif->csa_work); 332 + } 341 333 } 342 334 EXPORT_SYMBOL_GPL(mt792x_unassign_vif_chanctx); 343 335 ··· 632 614 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | 633 615 BIT(NL80211_IFTYPE_AP) | 634 616 BIT(NL80211_IFTYPE_P2P_CLIENT) | 635 - BIT(NL80211_IFTYPE_P2P_GO); 617 + BIT(NL80211_IFTYPE_P2P_GO) | 618 + BIT(NL80211_IFTYPE_P2P_DEVICE); 636 619 wiphy->max_remain_on_channel_duration = 5000; 637 620 wiphy->max_scan_ie_len = MT76_CONNAC_SCAN_IE_LEN; 638 621 wiphy->max_scan_ssids = 4; ··· 665 646 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); 666 647 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW); 667 648 ieee80211_hw_set(hw, CONNECTION_MONITOR); 649 + ieee80211_hw_set(hw, CHANCTX_STA_CSA); 668 650 669 651 if (dev->pm.enable) 670 652 ieee80211_hw_set(hw, CONNECTION_MONITOR); ··· 930 910 return 0; 931 911 } 932 912 EXPORT_SYMBOL_GPL(mt792x_load_firmware); 913 + 914 + void mt792x_config_mac_addr_list(struct mt792x_dev *dev) 915 + { 916 + struct ieee80211_hw *hw = mt76_hw(dev); 917 + struct wiphy *wiphy = hw->wiphy; 918 + int i; 919 + 920 + for (i = 0; i < ARRAY_SIZE(dev->macaddr_list); i++) { 921 + u8 *addr = dev->macaddr_list[i].addr; 922 + 923 + memcpy(addr, dev->mphy.macaddr, ETH_ALEN); 924 + 925 + if (!i) 926 + continue; 927 + 928 + addr[0] |= BIT(1); 929 + addr[0] ^= ((i - 1) << 2); 930 + } 931 + wiphy->addresses = dev->macaddr_list; 932 + wiphy->n_addresses = ARRAY_SIZE(dev->macaddr_list); 933 + } 934 + EXPORT_SYMBOL_GPL(mt792x_config_mac_addr_list); 933 935 934 936 MODULE_DESCRIPTION("MediaTek MT792x core driver"); 935 937 MODULE_LICENSE("Dual BSD/GPL");
+1 -1
drivers/net/wireless/mediatek/mt76/mt792x_mac.c
··· 153 153 return NULL; 154 154 155 155 link = container_of(wcid, struct mt792x_link_sta, wcid); 156 - sta = container_of(link, struct mt792x_sta, deflink); 156 + sta = link->sta; 157 157 if (!sta->vif) 158 158 return NULL; 159 159
+90 -60
drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c
··· 51 51 mt7996_sys_recovery_set(struct file *file, const char __user *user_buf, 52 52 size_t count, loff_t *ppos) 53 53 { 54 - struct mt7996_phy *phy = file->private_data; 55 - struct mt7996_dev *dev = phy->dev; 56 - bool band = phy->mt76->band_idx; 57 - char buf[16]; 54 + struct mt7996_dev *dev = file->private_data; 55 + char buf[16], *sep; 58 56 int ret = 0; 59 - u16 val; 57 + u16 band, val; 60 58 61 59 if (count >= sizeof(buf)) 62 60 return -EINVAL; ··· 67 69 else 68 70 buf[count] = '\0'; 69 71 70 - if (kstrtou16(buf, 0, &val)) 72 + sep = strchr(buf, ','); 73 + if (!sep) 74 + return -EINVAL; 75 + 76 + *sep = 0; 77 + if (kstrtou16(buf, 0, &band) || kstrtou16(sep + 1, 0, &val)) 71 78 return -EINVAL; 72 79 73 80 switch (val) { 74 81 /* 75 - * 0: grab firmware current SER state. 76 - * 1: trigger & enable system error L1 recovery. 77 - * 2: trigger & enable system error L2 recovery. 78 - * 3: trigger & enable system error L3 rx abort. 79 - * 4: trigger & enable system error L3 tx abort 80 - * 5: trigger & enable system error L3 tx disable. 81 - * 6: trigger & enable system error L3 bf recovery. 82 - * 7: trigger & enable system error L4 mdp recovery. 83 - * 8: trigger & enable system error full recovery. 84 - * 9: trigger firmware crash. 82 + * <band>,0: grab firmware current SER state. 83 + * <band>,1: trigger & enable system error L1 recovery. 84 + * <band>,2: trigger & enable system error L2 recovery. 85 + * <band>,3: trigger & enable system error L3 rx abort. 86 + * <band>,4: trigger & enable system error L3 tx abort 87 + * <band>,5: trigger & enable system error L3 tx disable. 88 + * <band>,6: trigger & enable system error L3 bf recovery. 89 + * <band>,7: trigger & enable system error L4 mdp recovery. 90 + * <band>,8: trigger & enable system error full recovery. 91 + * <band>,9: trigger firmware crash. 85 92 */ 86 93 case UNI_CMD_SER_QUERY: 87 94 ret = mt7996_mcu_set_ser(dev, UNI_CMD_SER_QUERY, 0, band); ··· 129 126 mt7996_sys_recovery_get(struct file *file, char __user *user_buf, 130 127 size_t count, loff_t *ppos) 131 128 { 132 - struct mt7996_phy *phy = file->private_data; 133 - struct mt7996_dev *dev = phy->dev; 129 + struct mt7996_dev *dev = file->private_data; 134 130 char *buff; 135 131 int desc = 0; 136 132 ssize_t ret; ··· 143 141 desc += scnprintf(buff + desc, bufsz - desc, 144 142 "Please echo the correct value ...\n"); 145 143 desc += scnprintf(buff + desc, bufsz - desc, 146 - "0: grab firmware transient SER state\n"); 144 + "<band>,0: grab firmware transient SER state\n"); 147 145 desc += scnprintf(buff + desc, bufsz - desc, 148 - "1: trigger system error L1 recovery\n"); 146 + "<band>,1: trigger system error L1 recovery\n"); 149 147 desc += scnprintf(buff + desc, bufsz - desc, 150 - "2: trigger system error L2 recovery\n"); 148 + "<band>,2: trigger system error L2 recovery\n"); 151 149 desc += scnprintf(buff + desc, bufsz - desc, 152 - "3: trigger system error L3 rx abort\n"); 150 + "<band>,3: trigger system error L3 rx abort\n"); 153 151 desc += scnprintf(buff + desc, bufsz - desc, 154 - "4: trigger system error L3 tx abort\n"); 152 + "<band>,4: trigger system error L3 tx abort\n"); 155 153 desc += scnprintf(buff + desc, bufsz - desc, 156 - "5: trigger system error L3 tx disable\n"); 154 + "<band>,5: trigger system error L3 tx disable\n"); 157 155 desc += scnprintf(buff + desc, bufsz - desc, 158 - "6: trigger system error L3 bf recovery\n"); 156 + "<band>,6: trigger system error L3 bf recovery\n"); 159 157 desc += scnprintf(buff + desc, bufsz - desc, 160 - "7: trigger system error L4 mdp recovery\n"); 158 + "<band>,7: trigger system error L4 mdp recovery\n"); 161 159 desc += scnprintf(buff + desc, bufsz - desc, 162 - "8: trigger system error full recovery\n"); 160 + "<band>,8: trigger system error full recovery\n"); 163 161 desc += scnprintf(buff + desc, bufsz - desc, 164 - "9: trigger firmware crash\n"); 162 + "<band>,9: trigger firmware crash\n"); 165 163 166 164 /* SER statistics */ 167 165 desc += scnprintf(buff + desc, bufsz - desc, ··· 526 524 seq_puts(s, "\n"); 527 525 } 528 526 529 - static int 530 - mt7996_tx_stats_show(struct seq_file *file, void *data) 527 + static void 528 + mt7996_tx_stats_show_phy(struct seq_file *file, struct mt7996_phy *phy) 531 529 { 532 - struct mt7996_phy *phy = file->private; 533 - struct mt7996_dev *dev = phy->dev; 534 530 struct mt76_mib_stats *mib = &phy->mib; 535 - int i; 536 531 u32 attempts, success, per; 537 - 538 - mutex_lock(&dev->mt76.mutex); 532 + int i; 539 533 540 534 mt7996_mac_update_stats(phy); 541 535 mt7996_ampdu_stat_read_phy(phy, file); ··· 556 558 else 557 559 seq_puts(file, "\n"); 558 560 } 561 + } 562 + 563 + static int 564 + mt7996_tx_stats_show(struct seq_file *file, void *data) 565 + { 566 + struct mt7996_dev *dev = file->private; 567 + struct mt7996_phy *phy = &dev->phy; 568 + 569 + mutex_lock(&dev->mt76.mutex); 570 + 571 + mt7996_tx_stats_show_phy(file, phy); 572 + phy = mt7996_phy2(dev); 573 + if (phy) 574 + mt7996_tx_stats_show_phy(file, phy); 575 + phy = mt7996_phy3(dev); 576 + if (phy) 577 + mt7996_tx_stats_show_phy(file, phy); 559 578 560 579 mutex_unlock(&dev->mt76.mutex); 561 580 ··· 616 601 mt7996_sta_hw_queue_read(void *data, struct ieee80211_sta *sta) 617 602 { 618 603 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; 619 - struct mt7996_dev *dev = msta->vif->phy->dev; 604 + struct mt7996_dev *dev = msta->vif->deflink.phy->dev; 620 605 struct seq_file *s = data; 621 606 u8 ac; 622 607 ··· 636 621 GENMASK(11, 0)); 637 622 seq_printf(s, "\tSTA %pM wcid %d: AC%d%d queued:%d\n", 638 623 sta->addr, msta->wcid.idx, 639 - msta->vif->mt76.wmm_idx, ac, qlen); 624 + msta->vif->deflink.mt76.wmm_idx, ac, qlen); 640 625 } 641 626 } 642 627 643 628 static int 644 629 mt7996_hw_queues_show(struct seq_file *file, void *data) 645 630 { 646 - struct mt7996_phy *phy = file->private; 647 - struct mt7996_dev *dev = phy->dev; 631 + struct mt7996_dev *dev = file->private; 632 + struct mt7996_phy *phy = &dev->phy; 648 633 static const struct hw_queue_map ple_queue_map[] = { 649 634 { "CPU_Q0", 0, 1, MT_CTX0 }, 650 635 { "CPU_Q1", 1, 1, MT_CTX0 + 1 }, ··· 700 685 /* iterate per-sta ple queue */ 701 686 ieee80211_iterate_stations_atomic(phy->mt76->hw, 702 687 mt7996_sta_hw_queue_read, file); 688 + phy = mt7996_phy2(dev); 689 + if (phy) 690 + ieee80211_iterate_stations_atomic(phy->mt76->hw, 691 + mt7996_sta_hw_queue_read, file); 692 + phy = mt7996_phy3(dev); 693 + if (phy) 694 + ieee80211_iterate_stations_atomic(phy->mt76->hw, 695 + mt7996_sta_hw_queue_read, file); 696 + 703 697 /* pse queue */ 704 698 seq_puts(file, "PSE non-empty queue info:\n"); 705 699 mt7996_hw_queue_read(file, ARRAY_SIZE(pse_queue_map), ··· 722 698 static int 723 699 mt7996_xmit_queues_show(struct seq_file *file, void *data) 724 700 { 725 - struct mt7996_phy *phy = file->private; 726 - struct mt7996_dev *dev = phy->dev; 701 + struct mt7996_dev *dev = file->private; 702 + struct mt7996_phy *phy; 727 703 struct { 728 704 struct mt76_queue *q; 729 705 char *queue; 730 706 } queue_map[] = { 731 - { phy->mt76->q_tx[MT_TXQ_BE], " MAIN" }, 707 + { dev->mphy.q_tx[MT_TXQ_BE], " MAIN0" }, 708 + { NULL, " MAIN1" }, 709 + { NULL, " MAIN2" }, 732 710 { dev->mt76.q_mcu[MT_MCUQ_WM], " MCUWM" }, 733 711 { dev->mt76.q_mcu[MT_MCUQ_WA], " MCUWA" }, 734 712 { dev->mt76.q_mcu[MT_MCUQ_FWDL], "MCUFWDL" }, 735 713 }; 736 714 int i; 715 + 716 + phy = mt7996_phy2(dev); 717 + if (phy) 718 + queue_map[1].q = phy->mt76->q_tx[MT_TXQ_BE]; 719 + 720 + phy = mt7996_phy3(dev); 721 + if (phy) 722 + queue_map[2].q = phy->mt76->q_tx[MT_TXQ_BE]; 737 723 738 724 seq_puts(file, " queue | hw-queued | head | tail |\n"); 739 725 for (i = 0; i < ARRAY_SIZE(queue_map); i++) { ··· 819 785 DEFINE_DEBUGFS_ATTRIBUTE(fops_rf_regval, mt7996_rf_regval_get, 820 786 mt7996_rf_regval_set, "0x%08llx\n"); 821 787 822 - int mt7996_init_debugfs(struct mt7996_phy *phy) 788 + int mt7996_init_debugfs(struct mt7996_dev *dev) 823 789 { 824 - struct mt7996_dev *dev = phy->dev; 825 790 struct dentry *dir; 826 791 827 - dir = mt76_register_debugfs_fops(phy->mt76, NULL); 792 + dir = mt76_register_debugfs_fops(&dev->mphy, NULL); 828 793 if (!dir) 829 794 return -ENOMEM; 830 - debugfs_create_file("hw-queues", 0400, dir, phy, 795 + 796 + debugfs_create_file("hw-queues", 0400, dir, dev, 831 797 &mt7996_hw_queues_fops); 832 - debugfs_create_file("xmit-queues", 0400, dir, phy, 798 + debugfs_create_file("xmit-queues", 0400, dir, dev, 833 799 &mt7996_xmit_queues_fops); 834 - debugfs_create_file("tx_stats", 0400, dir, phy, &mt7996_tx_stats_fops); 835 - debugfs_create_file("sys_recovery", 0600, dir, phy, 800 + debugfs_create_file("tx_stats", 0400, dir, dev, &mt7996_tx_stats_fops); 801 + debugfs_create_file("sys_recovery", 0600, dir, dev, 836 802 &mt7996_sys_recovery_ops); 837 803 debugfs_create_file("fw_debug_wm", 0600, dir, dev, &fops_fw_debug_wm); 838 804 debugfs_create_file("fw_debug_wa", 0600, dir, dev, &fops_fw_debug_wa); ··· 846 812 mt7996_twt_stats); 847 813 debugfs_create_file("rf_regval", 0600, dir, dev, &fops_rf_regval); 848 814 849 - if (phy->mt76->cap.has_5ghz) { 850 - debugfs_create_u32("dfs_hw_pattern", 0400, dir, 851 - &dev->hw_pattern); 852 - debugfs_create_file("radar_trigger", 0200, dir, dev, 853 - &fops_radar_trigger); 854 - debugfs_create_devm_seqfile(dev->mt76.dev, "rdd_monitor", dir, 855 - mt7996_rdd_monitor); 856 - } 815 + debugfs_create_u32("dfs_hw_pattern", 0400, dir, &dev->hw_pattern); 816 + debugfs_create_file("radar_trigger", 0200, dir, dev, 817 + &fops_radar_trigger); 818 + debugfs_create_devm_seqfile(dev->mt76.dev, "rdd_monitor", dir, 819 + mt7996_rdd_monitor); 857 820 858 - if (phy == &dev->phy) 859 - dev->debugfs_dir = dir; 821 + dev->debugfs_dir = dir; 860 822 861 823 return 0; 862 824 } ··· 929 899 #define LONG_PREAMBLE 1 930 900 struct ieee80211_sta *sta = file->private_data; 931 901 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; 932 - struct mt7996_dev *dev = msta->vif->phy->dev; 902 + struct mt7996_dev *dev = msta->vif->deflink.phy->dev; 933 903 struct ra_rate phy = {}; 934 904 char buf[100]; 935 905 int ret;
+154 -62
drivers/net/wireless/mediatek/mt76/mt7996/eeprom.c
··· 25 25 static char *mt7996_eeprom_name(struct mt7996_dev *dev) 26 26 { 27 27 switch (mt76_chip(&dev->mt76)) { 28 - case 0x7990: 29 - return MT7996_EEPROM_DEFAULT; 30 28 case 0x7992: 31 - return MT7992_EEPROM_DEFAULT; 29 + switch (dev->var.type) { 30 + case MT7992_VAR_TYPE_23: 31 + if (dev->var.fem == MT7996_FEM_INT) 32 + return MT7992_EEPROM_DEFAULT_23_INT; 33 + return MT7992_EEPROM_DEFAULT_23; 34 + case MT7992_VAR_TYPE_44: 35 + default: 36 + if (dev->var.fem == MT7996_FEM_INT) 37 + return MT7992_EEPROM_DEFAULT_INT; 38 + if (dev->var.fem == MT7996_FEM_MIX) 39 + return MT7992_EEPROM_DEFAULT_MIX; 40 + return MT7992_EEPROM_DEFAULT; 41 + } 42 + case 0x7990: 32 43 default: 33 - return MT7996_EEPROM_DEFAULT; 44 + switch (dev->var.type) { 45 + case MT7996_VAR_TYPE_233: 46 + if (dev->var.fem == MT7996_FEM_INT) 47 + return MT7996_EEPROM_DEFAULT_233_INT; 48 + return MT7996_EEPROM_DEFAULT_233; 49 + case MT7996_VAR_TYPE_444: 50 + default: 51 + if (dev->var.fem == MT7996_FEM_INT) 52 + return MT7996_EEPROM_DEFAULT_INT; 53 + return MT7996_EEPROM_DEFAULT; 54 + } 34 55 } 35 56 } 36 57 58 + static void 59 + mt7996_eeprom_parse_stream(const u8 *eeprom, u8 band_idx, u8 *path, 60 + u8 *rx_path, u8 *nss) 61 + { 62 + switch (band_idx) { 63 + case MT_BAND1: 64 + *path = FIELD_GET(MT_EE_WIFI_CONF2_TX_PATH_BAND1, 65 + eeprom[MT_EE_WIFI_CONF + 2]); 66 + *rx_path = FIELD_GET(MT_EE_WIFI_CONF3_RX_PATH_BAND1, 67 + eeprom[MT_EE_WIFI_CONF + 3]); 68 + *nss = FIELD_GET(MT_EE_WIFI_CONF5_STREAM_NUM_BAND1, 69 + eeprom[MT_EE_WIFI_CONF + 5]); 70 + break; 71 + case MT_BAND2: 72 + *path = FIELD_GET(MT_EE_WIFI_CONF2_TX_PATH_BAND2, 73 + eeprom[MT_EE_WIFI_CONF + 2]); 74 + *rx_path = FIELD_GET(MT_EE_WIFI_CONF4_RX_PATH_BAND2, 75 + eeprom[MT_EE_WIFI_CONF + 4]); 76 + *nss = FIELD_GET(MT_EE_WIFI_CONF5_STREAM_NUM_BAND2, 77 + eeprom[MT_EE_WIFI_CONF + 5]); 78 + break; 79 + default: 80 + *path = FIELD_GET(MT_EE_WIFI_CONF1_TX_PATH_BAND0, 81 + eeprom[MT_EE_WIFI_CONF + 1]); 82 + *rx_path = FIELD_GET(MT_EE_WIFI_CONF3_RX_PATH_BAND0, 83 + eeprom[MT_EE_WIFI_CONF + 3]); 84 + *nss = FIELD_GET(MT_EE_WIFI_CONF4_STREAM_NUM_BAND0, 85 + eeprom[MT_EE_WIFI_CONF + 4]); 86 + break; 87 + } 88 + } 89 + 90 + static bool mt7996_eeprom_variant_valid(struct mt7996_dev *dev, const u8 *def) 91 + { 92 + #define FEM_INT 0 93 + #define FEM_EXT 3 94 + u8 *eeprom = dev->mt76.eeprom.data, fem[2]; 95 + int i; 96 + 97 + for (i = 0; i < 2; i++) 98 + fem[i] = u8_get_bits(eeprom[MT_EE_WIFI_CONF + 6 + i], 99 + MT_EE_WIFI_PA_LNA_CONFIG); 100 + 101 + if (dev->var.fem == MT7996_FEM_EXT && 102 + !(fem[0] == FEM_EXT && fem[1] == FEM_EXT)) 103 + return false; 104 + else if (dev->var.fem == MT7996_FEM_INT && 105 + !(fem[0] == FEM_INT && fem[1] == FEM_INT)) 106 + return false; 107 + else if (dev->var.fem == MT7996_FEM_MIX && 108 + !(fem[0] == FEM_INT && fem[1] == FEM_EXT)) 109 + return false; 110 + 111 + for (i = 0; i < __MT_MAX_BAND; i++) { 112 + u8 path, rx_path, nss; 113 + u8 def_path, def_rx_path, def_nss; 114 + 115 + if (!dev->mt76.phys[i]) 116 + continue; 117 + 118 + mt7996_eeprom_parse_stream(eeprom, i, &path, &rx_path, &nss); 119 + mt7996_eeprom_parse_stream(def, i, &def_path, &def_rx_path, 120 + &def_nss); 121 + if (path > def_path || rx_path > def_rx_path || nss > def_nss) 122 + return false; 123 + } 124 + 125 + return true; 126 + } 127 + 37 128 static int 38 - mt7996_eeprom_load_default(struct mt7996_dev *dev) 129 + mt7996_eeprom_check_or_use_default(struct mt7996_dev *dev, bool use_default) 39 130 { 40 131 u8 *eeprom = dev->mt76.eeprom.data; 41 132 const struct firmware *fw = NULL; ··· 142 51 goto out; 143 52 } 144 53 54 + if (!use_default && mt7996_eeprom_variant_valid(dev, fw->data)) 55 + goto out; 56 + 57 + dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n"); 145 58 memcpy(eeprom, fw->data, MT7996_EEPROM_SIZE); 146 59 dev->flash_mode = true; 147 60 ··· 157 62 158 63 static int mt7996_eeprom_load(struct mt7996_dev *dev) 159 64 { 65 + bool use_default = false; 160 66 int ret; 161 67 162 68 ret = mt76_eeprom_init(&dev->mt76, MT7996_EEPROM_SIZE); 163 69 if (ret < 0) 164 70 return ret; 165 71 166 - if (ret) { 72 + if (ret && !mt7996_check_eeprom(dev)) { 167 73 dev->flash_mode = true; 168 - } else { 169 - u8 free_block_num; 170 - u32 block_num, i; 171 - u32 eeprom_blk_size = MT7996_EEPROM_BLOCK_SIZE; 74 + goto out; 75 + } 172 76 77 + if (!dev->flash_mode) { 78 + u32 eeprom_blk_size = MT7996_EEPROM_BLOCK_SIZE; 79 + u32 block_num = DIV_ROUND_UP(MT7996_EEPROM_SIZE, eeprom_blk_size); 80 + u8 free_block_num; 81 + int i; 82 + 83 + memset(dev->mt76.eeprom.data, 0, MT7996_EEPROM_SIZE); 173 84 ret = mt7996_mcu_get_eeprom_free_block(dev, &free_block_num); 174 85 if (ret < 0) 175 86 return ret; 176 87 177 88 /* efuse info isn't enough */ 178 - if (free_block_num >= 59) 179 - return -EINVAL; 89 + if (free_block_num >= 59) { 90 + use_default = true; 91 + goto out; 92 + } 180 93 181 - /* read eeprom data from efuse */ 182 - block_num = DIV_ROUND_UP(MT7996_EEPROM_SIZE, eeprom_blk_size); 183 - for (i = 0; i < block_num; i++) { 184 - ret = mt7996_mcu_get_eeprom(dev, i * eeprom_blk_size); 185 - if (ret < 0) 186 - return ret; 94 + /* check if eeprom data from fw is valid */ 95 + if (mt7996_mcu_get_eeprom(dev, 0, NULL, 0) || 96 + mt7996_check_eeprom(dev)) { 97 + use_default = true; 98 + goto out; 99 + } 100 + 101 + /* read eeprom data from fw */ 102 + for (i = 1; i < block_num; i++) { 103 + u32 len = eeprom_blk_size; 104 + 105 + if (i == block_num - 1) 106 + len = MT7996_EEPROM_SIZE % eeprom_blk_size; 107 + ret = mt7996_mcu_get_eeprom(dev, i * eeprom_blk_size, 108 + NULL, len); 109 + if (ret && ret != -EINVAL) { 110 + use_default = true; 111 + goto out; 112 + } 187 113 } 188 114 } 189 115 190 - return mt7996_check_eeprom(dev); 116 + out: 117 + return mt7996_eeprom_check_or_use_default(dev, use_default); 191 118 } 192 119 193 - static int mt7996_eeprom_parse_efuse_hw_cap(struct mt7996_dev *dev) 120 + static int mt7996_eeprom_parse_efuse_hw_cap(struct mt7996_phy *phy, 121 + u8 *path, u8 *rx_path, u8 *nss) 194 122 { 195 123 #define MODE_HE_ONLY BIT(0) 196 124 #define WTBL_SIZE_GROUP GENMASK(31, 28) 125 + #define STREAM_CAP(_offs) ((cap & (0x7 << (_offs))) >> (_offs)) 126 + struct mt7996_dev *dev = phy->dev; 197 127 u32 cap = 0; 198 128 int ret; 199 129 ··· 227 107 return ret; 228 108 229 109 if (cap) { 110 + u8 band_offs = phy->mt76->band_idx * 3; 111 + 230 112 dev->has_eht = !(cap & MODE_HE_ONLY); 231 113 dev->wtbl_size_group = u32_get_bits(cap, WTBL_SIZE_GROUP); 114 + *nss = min_t(u8, *nss, STREAM_CAP(1 + band_offs)); 115 + *path = min_t(u8, *path, STREAM_CAP(10 + band_offs)); 116 + *rx_path = min_t(u8, *rx_path, STREAM_CAP(19 + band_offs)); 232 117 } 233 118 234 - if (dev->wtbl_size_group < 2 || dev->wtbl_size_group > 4 || 235 - is_mt7992(&dev->mt76)) 236 - dev->wtbl_size_group = 2; /* set default */ 119 + if (dev->wtbl_size_group < 2 || dev->wtbl_size_group > 4) 120 + dev->wtbl_size_group = is_mt7996(&dev->mt76) ? 4 : 2; 237 121 238 122 return 0; 239 123 } ··· 287 163 int max_path = 5, max_nss = 4; 288 164 int ret; 289 165 290 - switch (band_idx) { 291 - case MT_BAND1: 292 - path = FIELD_GET(MT_EE_WIFI_CONF2_TX_PATH_BAND1, 293 - eeprom[MT_EE_WIFI_CONF + 2]); 294 - rx_path = FIELD_GET(MT_EE_WIFI_CONF3_RX_PATH_BAND1, 295 - eeprom[MT_EE_WIFI_CONF + 3]); 296 - nss = FIELD_GET(MT_EE_WIFI_CONF5_STREAM_NUM_BAND1, 297 - eeprom[MT_EE_WIFI_CONF + 5]); 298 - break; 299 - case MT_BAND2: 300 - path = FIELD_GET(MT_EE_WIFI_CONF2_TX_PATH_BAND2, 301 - eeprom[MT_EE_WIFI_CONF + 2]); 302 - rx_path = FIELD_GET(MT_EE_WIFI_CONF4_RX_PATH_BAND2, 303 - eeprom[MT_EE_WIFI_CONF + 4]); 304 - nss = FIELD_GET(MT_EE_WIFI_CONF5_STREAM_NUM_BAND2, 305 - eeprom[MT_EE_WIFI_CONF + 5]); 306 - break; 307 - default: 308 - path = FIELD_GET(MT_EE_WIFI_CONF1_TX_PATH_BAND0, 309 - eeprom[MT_EE_WIFI_CONF + 1]); 310 - rx_path = FIELD_GET(MT_EE_WIFI_CONF3_RX_PATH_BAND0, 311 - eeprom[MT_EE_WIFI_CONF + 3]); 312 - nss = FIELD_GET(MT_EE_WIFI_CONF4_STREAM_NUM_BAND0, 313 - eeprom[MT_EE_WIFI_CONF + 4]); 314 - break; 315 - } 166 + mt7996_eeprom_parse_stream(eeprom, band_idx, &path, &rx_path, &nss); 167 + ret = mt7996_eeprom_parse_efuse_hw_cap(phy, &path, &rx_path, &nss); 168 + if (ret) 169 + return ret; 316 170 317 171 if (!path || path > max_path) 318 172 path = max_path; ··· 305 203 306 204 mphy->antenna_mask = BIT(nss) - 1; 307 205 mphy->chainmask = (BIT(path) - 1) << dev->chainshift[band_idx]; 206 + phy->orig_chainmask = mphy->chainmask; 308 207 dev->chainmask |= mphy->chainmask; 309 208 if (band_idx < MT_BAND2) 310 209 dev->chainshift[band_idx + 1] = dev->chainshift[band_idx] + 311 210 hweight16(mphy->chainmask); 312 - 313 - ret = mt7996_eeprom_parse_efuse_hw_cap(dev); 314 - if (ret) 315 - return ret; 316 211 317 212 return mt7996_eeprom_parse_band_config(phy); 318 213 } ··· 319 220 int ret; 320 221 321 222 ret = mt7996_eeprom_load(dev); 322 - if (ret < 0) { 323 - if (ret != -EINVAL) 324 - return ret; 325 - 326 - dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n"); 327 - ret = mt7996_eeprom_load_default(dev); 328 - if (ret) 329 - return ret; 330 - } 223 + if (ret < 0) 224 + return ret; 331 225 332 226 ret = mt7996_eeprom_parse_hw_cap(dev, &dev->phy); 333 227 if (ret < 0)
+2
drivers/net/wireless/mediatek/mt76/mt7996/eeprom.h
··· 40 40 #define MT_EE_WIFI_CONF5_STREAM_NUM_BAND1 GENMASK(2, 0) 41 41 #define MT_EE_WIFI_CONF5_STREAM_NUM_BAND2 GENMASK(5, 3) 42 42 43 + #define MT_EE_WIFI_PA_LNA_CONFIG GENMASK(1, 0) 44 + 43 45 #define MT_EE_RATE_DELTA_MASK GENMASK(5, 0) 44 46 #define MT_EE_RATE_DELTA_SIGN BIT(6) 45 47 #define MT_EE_RATE_DELTA_EN BIT(7)
+274 -134
drivers/net/wireless/mediatek/mt76/mt7996/init.c
··· 14 14 #include "coredump.h" 15 15 #include "eeprom.h" 16 16 17 + static const struct ieee80211_iface_limit if_limits_global = { 18 + .max = MT7996_MAX_INTERFACES * MT7996_MAX_RADIOS, 19 + .types = BIT(NL80211_IFTYPE_STATION) 20 + | BIT(NL80211_IFTYPE_ADHOC) 21 + | BIT(NL80211_IFTYPE_AP) 22 + #ifdef CONFIG_MAC80211_MESH 23 + | BIT(NL80211_IFTYPE_MESH_POINT) 24 + #endif 25 + }; 26 + 27 + static const struct ieee80211_iface_combination if_comb_global = { 28 + .limits = &if_limits_global, 29 + .n_limits = 1, 30 + .max_interfaces = MT7996_MAX_INTERFACES * MT7996_MAX_RADIOS, 31 + .num_different_channels = MT7996_MAX_RADIOS, 32 + .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | 33 + BIT(NL80211_CHAN_WIDTH_20) | 34 + BIT(NL80211_CHAN_WIDTH_40) | 35 + BIT(NL80211_CHAN_WIDTH_80) | 36 + BIT(NL80211_CHAN_WIDTH_160), 37 + }; 38 + 17 39 static const struct ieee80211_iface_limit if_limits[] = { 18 40 { 19 41 .max = 16, ··· 49 27 } 50 28 }; 51 29 52 - static const struct ieee80211_iface_combination if_comb[] = { 53 - { 54 - .limits = if_limits, 55 - .n_limits = ARRAY_SIZE(if_limits), 56 - .max_interfaces = MT7996_MAX_INTERFACES, 57 - .num_different_channels = 1, 58 - .beacon_int_infra_match = true, 59 - .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | 60 - BIT(NL80211_CHAN_WIDTH_20) | 61 - BIT(NL80211_CHAN_WIDTH_40) | 62 - BIT(NL80211_CHAN_WIDTH_80) | 63 - BIT(NL80211_CHAN_WIDTH_160), 64 - .beacon_int_min_gcd = 100, 65 - } 30 + static const struct ieee80211_iface_combination if_comb = { 31 + .limits = if_limits, 32 + .n_limits = ARRAY_SIZE(if_limits), 33 + .max_interfaces = MT7996_MAX_INTERFACES, 34 + .num_different_channels = 1, 35 + .beacon_int_infra_match = true, 36 + .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | 37 + BIT(NL80211_CHAN_WIDTH_20) | 38 + BIT(NL80211_CHAN_WIDTH_40) | 39 + BIT(NL80211_CHAN_WIDTH_80) | 40 + BIT(NL80211_CHAN_WIDTH_160), 41 + .beacon_int_min_gcd = 100, 66 42 }; 67 43 68 44 static ssize_t mt7996_thermal_temp_show(struct device *dev, ··· 102 82 return ret; 103 83 104 84 mutex_lock(&phy->dev->mt76.mutex); 105 - val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 40, 130); 85 + val = DIV_ROUND_CLOSEST(clamp_val(val, 40 * 1000, 130 * 1000), 1000); 106 86 107 87 /* add a safety margin ~10 */ 108 88 if ((i - 1 == MT7996_CRIT_TEMP_IDX && ··· 197 177 static void mt7996_unregister_thermal(struct mt7996_phy *phy) 198 178 { 199 179 struct wiphy *wiphy = phy->mt76->hw->wiphy; 180 + char name[sizeof("cooling_deviceXXX")]; 200 181 201 182 if (!phy->cdev) 202 183 return; 203 184 204 - sysfs_remove_link(&wiphy->dev.kobj, "cooling_device"); 185 + snprintf(name, sizeof(name), "cooling_device%d", phy->mt76->band_idx); 186 + sysfs_remove_link(&wiphy->dev.kobj, name); 205 187 thermal_cooling_device_unregister(phy->cdev); 206 188 } 207 189 208 190 static int mt7996_thermal_init(struct mt7996_phy *phy) 209 191 { 210 192 struct wiphy *wiphy = phy->mt76->hw->wiphy; 193 + char cname[sizeof("cooling_deviceXXX")]; 211 194 struct thermal_cooling_device *cdev; 212 195 struct device *hwmon; 213 196 const char *name; 214 197 215 - name = devm_kasprintf(&wiphy->dev, GFP_KERNEL, "mt7996_%s", 216 - wiphy_name(wiphy)); 198 + name = devm_kasprintf(&wiphy->dev, GFP_KERNEL, "mt7996_%s.%d", 199 + wiphy_name(wiphy), phy->mt76->band_idx); 200 + snprintf(cname, sizeof(cname), "cooling_device%d", phy->mt76->band_idx); 217 201 218 202 cdev = thermal_cooling_device_register(name, phy, &mt7996_thermal_ops); 219 203 if (!IS_ERR(cdev)) { 220 204 if (sysfs_create_link(&wiphy->dev.kobj, &cdev->device.kobj, 221 - "cooling_device") < 0) 205 + cname) < 0) 222 206 thermal_cooling_device_unregister(cdev); 223 207 else 224 208 phy->cdev = cdev; ··· 354 330 { 355 331 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 356 332 struct mt7996_dev *dev = mt7996_hw_dev(hw); 357 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 333 + struct mt7996_phy *phy; 358 334 359 335 memcpy(dev->mt76.alpha2, request->alpha2, sizeof(dev->mt76.alpha2)); 360 336 dev->mt76.region = request->dfs_region; 361 337 362 - if (dev->mt76.region == NL80211_DFS_UNSET) 363 - mt7996_mcu_rdd_background_enable(phy, NULL); 338 + mt7996_for_each_phy(dev, phy) { 339 + if (dev->mt76.region == NL80211_DFS_UNSET) 340 + mt7996_mcu_rdd_background_enable(phy, NULL); 364 341 342 + mt7996_init_txpower(phy); 343 + phy->mt76->dfs_state = MT_DFS_STATE_UNKNOWN; 344 + mt7996_dfs_init_radar_detector(phy); 345 + } 346 + } 347 + 348 + static void 349 + mt7996_init_wiphy_band(struct ieee80211_hw *hw, struct mt7996_phy *phy) 350 + { 351 + struct mt7996_dev *dev = phy->dev; 352 + struct wiphy *wiphy = hw->wiphy; 353 + int n_radios = hw->wiphy->n_radio; 354 + struct wiphy_radio_freq_range *freq = &dev->radio_freqs[n_radios]; 355 + struct wiphy_radio *radio = &dev->radios[n_radios]; 356 + 357 + phy->slottime = 9; 358 + phy->beacon_rate = -1; 359 + 360 + if (phy->mt76->cap.has_2ghz) { 361 + phy->mt76->sband_2g.sband.ht_cap.cap |= 362 + IEEE80211_HT_CAP_LDPC_CODING | 363 + IEEE80211_HT_CAP_MAX_AMSDU; 364 + phy->mt76->sband_2g.sband.ht_cap.ampdu_density = 365 + IEEE80211_HT_MPDU_DENSITY_2; 366 + freq->start_freq = 2400000; 367 + freq->end_freq = 2500000; 368 + } else if (phy->mt76->cap.has_5ghz) { 369 + phy->mt76->sband_5g.sband.ht_cap.cap |= 370 + IEEE80211_HT_CAP_LDPC_CODING | 371 + IEEE80211_HT_CAP_MAX_AMSDU; 372 + 373 + phy->mt76->sband_5g.sband.vht_cap.cap |= 374 + IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | 375 + IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK | 376 + IEEE80211_VHT_CAP_SHORT_GI_160 | 377 + IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; 378 + phy->mt76->sband_5g.sband.ht_cap.ampdu_density = 379 + IEEE80211_HT_MPDU_DENSITY_1; 380 + 381 + ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW); 382 + freq->start_freq = 5000000; 383 + freq->end_freq = 5900000; 384 + } else if (phy->mt76->cap.has_6ghz) { 385 + freq->start_freq = 5900000; 386 + freq->end_freq = 7200000; 387 + } else { 388 + return; 389 + } 390 + 391 + dev->radio_phy[n_radios] = phy; 392 + radio->freq_range = freq; 393 + radio->n_freq_range = 1; 394 + radio->iface_combinations = &if_comb; 395 + radio->n_iface_combinations = 1; 396 + hw->wiphy->n_radio++; 397 + 398 + wiphy->available_antennas_rx |= phy->mt76->chainmask; 399 + wiphy->available_antennas_tx |= phy->mt76->chainmask; 400 + 401 + mt76_set_stream_caps(phy->mt76, true); 402 + mt7996_set_stream_vht_txbf_caps(phy); 403 + mt7996_set_stream_he_eht_caps(phy); 365 404 mt7996_init_txpower(phy); 366 - 367 - phy->mt76->dfs_state = MT_DFS_STATE_UNKNOWN; 368 - mt7996_dfs_init_radar_detector(phy); 369 405 } 370 406 371 407 static void 372 408 mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed) 373 409 { 374 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 375 - struct mt76_dev *mdev = &phy->dev->mt76; 410 + struct mt7996_dev *dev = mt7996_hw_dev(hw); 411 + struct mt76_dev *mdev = &dev->mt76; 376 412 struct wiphy *wiphy = hw->wiphy; 377 - u16 max_subframes = phy->dev->has_eht ? IEEE80211_MAX_AMPDU_BUF_EHT : 378 - IEEE80211_MAX_AMPDU_BUF_HE; 413 + u16 max_subframes = dev->has_eht ? IEEE80211_MAX_AMPDU_BUF_EHT : 414 + IEEE80211_MAX_AMPDU_BUF_HE; 379 415 380 416 hw->queues = 4; 381 417 hw->max_rx_aggregation_subframes = max_subframes; ··· 447 363 hw->radiotap_timestamp.units_pos = 448 364 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US; 449 365 450 - phy->slottime = 9; 451 - phy->beacon_rate = -1; 452 - 453 366 hw->sta_data_size = sizeof(struct mt7996_sta); 454 367 hw->vif_data_size = sizeof(struct mt7996_vif); 368 + hw->chanctx_data_size = sizeof(struct mt76_chanctx); 455 369 456 - wiphy->iface_combinations = if_comb; 457 - wiphy->n_iface_combinations = ARRAY_SIZE(if_comb); 370 + wiphy->iface_combinations = &if_comb_global; 371 + wiphy->n_iface_combinations = 1; 372 + 373 + wiphy->radio = dev->radios; 374 + 458 375 wiphy->reg_notifier = mt7996_regd_notifier; 459 376 wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; 460 377 wiphy->mbssid_max_interfaces = 16; ··· 472 387 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CAN_REPLACE_PTK0); 473 388 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER); 474 389 475 - if (!mdev->dev->of_node || 476 - !of_property_read_bool(mdev->dev->of_node, 477 - "mediatek,disable-radar-background")) 390 + if (mt7996_has_background_radar(dev) && 391 + (!mdev->dev->of_node || 392 + !of_property_read_bool(mdev->dev->of_node, 393 + "mediatek,disable-radar-background"))) 478 394 wiphy_ext_feature_set(wiphy, 479 395 NL80211_EXT_FEATURE_RADAR_BACKGROUND); 480 396 481 397 ieee80211_hw_set(hw, HAS_RATE_CONTROL); 482 398 ieee80211_hw_set(hw, SUPPORTS_TX_ENCAP_OFFLOAD); 483 399 ieee80211_hw_set(hw, SUPPORTS_RX_DECAP_OFFLOAD); 484 - ieee80211_hw_set(hw, WANT_MONITOR_VIF); 400 + ieee80211_hw_set(hw, NO_VIRTUAL_MONITOR); 485 401 ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID); 486 402 487 403 hw->max_tx_fragments = 4; 488 404 489 - if (phy->mt76->cap.has_2ghz) { 490 - phy->mt76->sband_2g.sband.ht_cap.cap |= 491 - IEEE80211_HT_CAP_LDPC_CODING | 492 - IEEE80211_HT_CAP_MAX_AMSDU; 493 - phy->mt76->sband_2g.sband.ht_cap.ampdu_density = 494 - IEEE80211_HT_MPDU_DENSITY_2; 495 - } 496 - 497 - if (phy->mt76->cap.has_5ghz) { 498 - phy->mt76->sband_5g.sband.ht_cap.cap |= 499 - IEEE80211_HT_CAP_LDPC_CODING | 500 - IEEE80211_HT_CAP_MAX_AMSDU; 501 - 502 - phy->mt76->sband_5g.sband.vht_cap.cap |= 503 - IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | 504 - IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK | 505 - IEEE80211_VHT_CAP_SHORT_GI_160 | 506 - IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; 507 - phy->mt76->sband_5g.sband.ht_cap.ampdu_density = 508 - IEEE80211_HT_MPDU_DENSITY_1; 509 - 510 - ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW); 511 - } 512 - 513 405 /* init led callbacks */ 514 406 if (IS_ENABLED(CONFIG_MT76_LEDS)) { 515 - phy->mt76->leds.cdev.brightness_set = mt7996_led_set_brightness; 516 - phy->mt76->leds.cdev.blink_set = mt7996_led_set_blink; 407 + dev->mphy.leds.cdev.brightness_set = mt7996_led_set_brightness; 408 + dev->mphy.leds.cdev.blink_set = mt7996_led_set_blink; 517 409 } 518 410 519 - mt76_set_stream_caps(phy->mt76, true); 520 - mt7996_set_stream_vht_txbf_caps(phy); 521 - mt7996_set_stream_he_eht_caps(phy); 522 - mt7996_init_txpower(phy); 411 + wiphy->max_scan_ssids = 4; 412 + wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN; 523 413 524 - wiphy->available_antennas_rx = phy->mt76->antenna_mask; 525 - wiphy->available_antennas_tx = phy->mt76->antenna_mask; 414 + mt7996_init_wiphy_band(hw, &dev->phy); 526 415 } 527 416 528 417 static void ··· 514 455 MT_WF_RMAC_MIB_QOS01_BACKOFF); 515 456 mt76_clear(dev, MT_WF_RMAC_MIB_AIRTIME4(band), 516 457 MT_WF_RMAC_MIB_QOS23_BACKOFF); 458 + 459 + /* clear backoff time for Tx duration */ 460 + mt76_clear(dev, MT_WTBLOFF_ACR(band), 461 + MT_WTBLOFF_ADM_BACKOFFTIME); 517 462 518 463 /* clear backoff time and set software compensation for OBSS time */ 519 464 mask = MT_WF_RMAC_MIB_OBSS_BACKOFF | MT_WF_RMAC_MIB_ED_OFFSET; ··· 617 554 return mt7996_mcu_set_txbf(dev, BF_HW_EN_UPDATE); 618 555 } 619 556 620 - static int mt7996_register_phy(struct mt7996_dev *dev, struct mt7996_phy *phy, 621 - enum mt76_band_id band) 557 + static int mt7996_register_phy(struct mt7996_dev *dev, enum mt76_band_id band) 622 558 { 559 + struct mt7996_phy *phy; 623 560 struct mt76_phy *mphy; 624 561 u32 mac_ofs, hif1_ofs = 0; 625 562 int ret; 626 563 struct mtk_wed_device *wed = &dev->mt76.mmio.wed; 627 564 628 - if (!mt7996_band_valid(dev, band) || band == MT_BAND0) 629 - return 0; 630 - 631 - if (phy) 565 + if (!mt7996_band_valid(dev, band)) 632 566 return 0; 633 567 634 568 if (is_mt7996(&dev->mt76) && band == MT_BAND2 && dev->hif2) { ··· 633 573 wed = &dev->mt76.mmio.wed_hif2; 634 574 } 635 575 636 - mphy = mt76_alloc_phy(&dev->mt76, sizeof(*phy), &mt7996_ops, band); 576 + mphy = mt76_alloc_radio_phy(&dev->mt76, sizeof(*phy), band); 637 577 if (!mphy) 638 578 return -ENOMEM; 639 579 ··· 664 604 mt76_eeprom_override(mphy); 665 605 666 606 /* init wiphy according to mphy and phy */ 667 - mt7996_init_wiphy(mphy->hw, wed); 607 + mt7996_init_wiphy_band(mphy->hw, phy); 668 608 ret = mt7996_init_tx_queues(mphy->priv, 669 609 MT_TXQ_ID(band), 670 610 MT7996_TX_RING_SIZE, ··· 675 615 676 616 ret = mt76_register_phy(mphy, true, mt76_rates, 677 617 ARRAY_SIZE(mt76_rates)); 678 - if (ret) 679 - goto error; 680 - 681 - ret = mt7996_thermal_init(phy); 682 - if (ret) 683 - goto error; 684 - 685 - ret = mt7996_init_debugfs(phy); 686 618 if (ret) 687 619 goto error; 688 620 ··· 689 637 690 638 error: 691 639 mphy->dev->phys[band] = NULL; 692 - ieee80211_free_hw(mphy->hw); 693 640 return ret; 694 641 } 695 642 696 643 static void 697 - mt7996_unregister_phy(struct mt7996_phy *phy, enum mt76_band_id band) 644 + mt7996_unregister_phy(struct mt7996_phy *phy) 698 645 { 699 - struct mt76_phy *mphy; 700 - 701 - if (!phy) 702 - return; 703 - 704 - mt7996_unregister_thermal(phy); 705 - 706 - mphy = phy->dev->mt76.phys[band]; 707 - mt76_unregister_phy(mphy); 708 - ieee80211_free_hw(mphy->hw); 709 - phy->dev->mt76.phys[band] = NULL; 646 + if (phy) 647 + mt7996_unregister_thermal(phy); 710 648 } 711 649 712 650 static void mt7996_init_work(struct work_struct *work) ··· 923 881 #endif 924 882 } 925 883 884 + static int mt7996_variant_type_init(struct mt7996_dev *dev) 885 + { 886 + u32 val = mt76_rr(dev, MT_PAD_GPIO); 887 + u8 var_type; 888 + 889 + switch (mt76_chip(&dev->mt76)) { 890 + case 0x7990: 891 + if (val & MT_PAD_GPIO_2ADIE_TBTC) 892 + var_type = MT7996_VAR_TYPE_233; 893 + else 894 + var_type = MT7996_VAR_TYPE_444; 895 + break; 896 + case 0x7992: 897 + if (val & MT_PAD_GPIO_ADIE_SINGLE) 898 + var_type = MT7992_VAR_TYPE_23; 899 + else if (u32_get_bits(val, MT_PAD_GPIO_ADIE_COMB_7992)) 900 + var_type = MT7992_VAR_TYPE_44; 901 + else 902 + return -EINVAL; 903 + break; 904 + default: 905 + return -EINVAL; 906 + } 907 + 908 + dev->var.type = var_type; 909 + return 0; 910 + } 911 + 912 + static int mt7996_variant_fem_init(struct mt7996_dev *dev) 913 + { 914 + #define MT7976C_EFUSE_OFFSET 0x470 915 + u8 buf[MT7996_EEPROM_BLOCK_SIZE], idx, adie_idx, adie_comb; 916 + u32 regval, val = mt76_rr(dev, MT_PAD_GPIO); 917 + u16 adie_id, adie_ver; 918 + bool is_7976c; 919 + int ret; 920 + 921 + if (is_mt7992(&dev->mt76)) { 922 + adie_idx = (val & MT_PAD_GPIO_ADIE_SINGLE) ? 0 : 1; 923 + adie_comb = u32_get_bits(val, MT_PAD_GPIO_ADIE_COMB_7992); 924 + } else { 925 + adie_idx = 0; 926 + adie_comb = u32_get_bits(val, MT_PAD_GPIO_ADIE_COMB); 927 + } 928 + 929 + ret = mt7996_mcu_rf_regval(dev, MT_ADIE_CHIP_ID(adie_idx), &regval, false); 930 + if (ret) 931 + return ret; 932 + 933 + ret = mt7996_mcu_get_eeprom(dev, MT7976C_EFUSE_OFFSET, buf, sizeof(buf)); 934 + if (ret && ret != -EINVAL) 935 + return ret; 936 + 937 + adie_ver = u32_get_bits(regval, MT_ADIE_VERSION_MASK); 938 + idx = MT7976C_EFUSE_OFFSET % MT7996_EEPROM_BLOCK_SIZE; 939 + is_7976c = adie_ver == 0x8a10 || adie_ver == 0x8b00 || 940 + adie_ver == 0x8c10 || buf[idx] == 0xc; 941 + 942 + adie_id = u32_get_bits(regval, MT_ADIE_CHIP_ID_MASK); 943 + if (adie_id == 0x7975 || adie_id == 0x7979 || 944 + (adie_id == 0x7976 && is_7976c)) 945 + dev->var.fem = MT7996_FEM_INT; 946 + else if (adie_id == 0x7977 && adie_comb == 1) 947 + dev->var.fem = MT7996_FEM_MIX; 948 + else 949 + dev->var.fem = MT7996_FEM_EXT; 950 + 951 + return 0; 952 + } 953 + 926 954 static int mt7996_init_hardware(struct mt7996_dev *dev) 927 955 { 928 956 int ret, idx; ··· 1008 896 INIT_LIST_HEAD(&dev->wed_rro.poll_list); 1009 897 spin_lock_init(&dev->wed_rro.lock); 1010 898 899 + ret = mt7996_variant_type_init(dev); 900 + if (ret) 901 + return ret; 902 + 1011 903 ret = mt7996_dma_init(dev); 1012 904 if (ret) 1013 905 return ret; ··· 1023 907 return ret; 1024 908 1025 909 ret = mt7996_wed_rro_init(dev); 910 + if (ret) 911 + return ret; 912 + 913 + ret = mt7996_variant_fem_init(dev); 1026 914 if (ret) 1027 915 return ret; 1028 916 ··· 1080 960 1081 961 static void 1082 962 mt7996_set_stream_he_txbf_caps(struct mt7996_phy *phy, 1083 - struct ieee80211_sta_he_cap *he_cap, int vif) 963 + struct ieee80211_sta_he_cap *he_cap, int vif, 964 + enum nl80211_band band) 1084 965 { 1085 966 struct ieee80211_he_cap_elem *elem = &he_cap->he_cap_elem; 1086 967 int sts = hweight16(phy->mt76->chainmask); 968 + bool non_2g = band != NL80211_BAND_2GHZ; 1087 969 u8 c; 1088 970 1089 971 #ifdef CONFIG_MAC80211_MESH ··· 1115 993 1116 994 if (is_mt7996(phy->mt76->dev)) 1117 995 c |= IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4 | 1118 - IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_4; 996 + (IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_4 * non_2g); 1119 997 else 1120 998 c |= IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_5 | 1121 - IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_5; 999 + (IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_5 * non_2g); 1122 1000 1123 1001 elem->phy_cap_info[4] |= c; 1124 1002 ··· 1144 1022 1145 1023 c = FIELD_PREP(IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK, 1146 1024 sts - 1) | 1147 - FIELD_PREP(IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK, 1148 - sts - 1); 1025 + (FIELD_PREP(IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK, 1026 + sts - 1) * non_2g); 1027 + 1149 1028 elem->phy_cap_info[5] |= c; 1150 1029 1151 1030 if (vif != NL80211_IFTYPE_AP) ··· 1158 1035 IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB; 1159 1036 elem->phy_cap_info[6] |= c; 1160 1037 1161 - c = IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ | 1162 - IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ; 1038 + c = 0; 1039 + if (non_2g) 1040 + c |= IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ | 1041 + IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ; 1163 1042 elem->phy_cap_info[7] |= c; 1164 1043 } 1165 1044 ··· 1202 1077 he_cap_elem->phy_cap_info[2] = IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | 1203 1078 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ; 1204 1079 1080 + he_cap_elem->phy_cap_info[7] = 1081 + IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI; 1082 + 1205 1083 switch (iftype) { 1206 1084 case NL80211_IFTYPE_AP: 1207 1085 he_cap_elem->mac_cap_info[0] |= IEEE80211_HE_MAC_CAP0_TWT_RES; ··· 1244 1116 IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE | 1245 1117 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT; 1246 1118 he_cap_elem->phy_cap_info[7] |= 1247 - IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP | 1248 - IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI; 1119 + IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP; 1249 1120 he_cap_elem->phy_cap_info[8] |= 1250 1121 IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G | 1251 1122 IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU | ··· 1267 1140 he_mcs->rx_mcs_160 = cpu_to_le16(mcs_map); 1268 1141 he_mcs->tx_mcs_160 = cpu_to_le16(mcs_map); 1269 1142 1270 - mt7996_set_stream_he_txbf_caps(phy, he_cap, iftype); 1143 + mt7996_set_stream_he_txbf_caps(phy, he_cap, iftype, band); 1271 1144 1272 1145 memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres)); 1273 1146 if (he_cap_elem->phy_cap_info[6] & 1274 1147 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 1275 - mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss); 1148 + mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss, band); 1276 1149 } else { 1277 1150 he_cap_elem->phy_cap_info[9] |= 1278 1151 u8_encode_bits(IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US, ··· 1314 1187 1315 1188 eht_cap_elem->mac_cap_info[0] = 1316 1189 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS | 1317 - IEEE80211_EHT_MAC_CAP0_OM_CONTROL; 1190 + IEEE80211_EHT_MAC_CAP0_OM_CONTROL | 1191 + u8_encode_bits(IEEE80211_EHT_MAC_CAP0_MAX_MPDU_LEN_11454, 1192 + IEEE80211_EHT_MAC_CAP0_MAX_MPDU_LEN_MASK); 1318 1193 1319 1194 eht_cap_elem->phy_cap_info[0] = 1320 1195 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI | ··· 1331 1202 1332 1203 eht_cap_elem->phy_cap_info[1] = 1333 1204 u8_encode_bits(u8_get_bits(val, GENMASK(2, 1)), 1334 - IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK) | 1335 - u8_encode_bits(val, 1336 - IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK); 1205 + IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK); 1337 1206 1338 1207 eht_cap_elem->phy_cap_info[2] = 1339 - u8_encode_bits(sts - 1, IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK) | 1340 - u8_encode_bits(sts - 1, IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK); 1208 + u8_encode_bits(sts - 1, IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK); 1209 + 1210 + if (band != NL80211_BAND_2GHZ) { 1211 + eht_cap_elem->phy_cap_info[1] |= 1212 + u8_encode_bits(val, 1213 + IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK); 1214 + 1215 + eht_cap_elem->phy_cap_info[2] |= 1216 + u8_encode_bits(sts - 1, 1217 + IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK); 1218 + } 1341 1219 1342 1220 if (band == NL80211_BAND_6GHZ) { 1343 1221 eht_cap_elem->phy_cap_info[0] |= ··· 1366 1230 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK; 1367 1231 1368 1232 eht_cap_elem->phy_cap_info[4] = 1233 + IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI | 1369 1234 u8_encode_bits(min_t(int, sts - 1, 2), 1370 1235 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK); 1371 1236 1372 1237 eht_cap_elem->phy_cap_info[5] = 1373 1238 u8_encode_bits(IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US, 1374 1239 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK) | 1375 - u8_encode_bits(u8_get_bits(0x11, GENMASK(1, 0)), 1240 + u8_encode_bits(u8_get_bits(1, GENMASK(1, 0)), 1376 1241 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK); 1377 1242 1378 1243 val = width == NL80211_CHAN_WIDTH_320 ? 0xf : 1379 1244 width == NL80211_CHAN_WIDTH_160 ? 0x7 : 1380 1245 width == NL80211_CHAN_WIDTH_80 ? 0x3 : 0x1; 1381 1246 eht_cap_elem->phy_cap_info[6] = 1382 - u8_encode_bits(u8_get_bits(0x11, GENMASK(4, 2)), 1383 - IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK) | 1384 1247 u8_encode_bits(val, IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK); 1385 1248 1386 1249 val = u8_encode_bits(nss, IEEE80211_EHT_MCS_NSS_RX) | ··· 1405 1270 1406 1271 eht_cap_elem->phy_cap_info[7] = 1407 1272 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ | 1273 + IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ; 1274 + 1275 + if (band == NL80211_BAND_2GHZ) 1276 + return; 1277 + 1278 + eht_cap_elem->phy_cap_info[7] |= 1408 1279 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ | 1409 - IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ | 1410 1280 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ; 1411 1281 1412 1282 if (band != NL80211_BAND_6GHZ) ··· 1470 1330 int mt7996_register_device(struct mt7996_dev *dev) 1471 1331 { 1472 1332 struct ieee80211_hw *hw = mt76_hw(dev); 1333 + struct mt7996_phy *phy; 1473 1334 int ret; 1474 1335 1475 1336 dev->phy.dev = dev; ··· 1492 1351 1493 1352 mt7996_init_wiphy(hw, &dev->mt76.mmio.wed); 1494 1353 1354 + ret = mt7996_register_phy(dev, MT_BAND1); 1355 + if (ret) 1356 + return ret; 1357 + 1358 + ret = mt7996_register_phy(dev, MT_BAND2); 1359 + if (ret) 1360 + return ret; 1361 + 1495 1362 ret = mt76_register_device(&dev->mt76, true, mt76_rates, 1496 1363 ARRAY_SIZE(mt76_rates)); 1497 1364 if (ret) 1498 1365 return ret; 1499 1366 1500 - ret = mt7996_thermal_init(&dev->phy); 1501 - if (ret) 1502 - return ret; 1503 - 1504 - ret = mt7996_register_phy(dev, mt7996_phy2(dev), MT_BAND1); 1505 - if (ret) 1506 - return ret; 1507 - 1508 - ret = mt7996_register_phy(dev, mt7996_phy3(dev), MT_BAND2); 1509 - if (ret) 1510 - return ret; 1367 + mt7996_for_each_phy(dev, phy) 1368 + mt7996_thermal_init(phy); 1511 1369 1512 1370 ieee80211_queue_work(mt76_hw(dev), &dev->init_work); 1513 1371 1514 1372 dev->recovery.hw_init_done = true; 1515 1373 1516 - ret = mt7996_init_debugfs(&dev->phy); 1374 + ret = mt7996_init_debugfs(dev); 1517 1375 if (ret) 1518 1376 goto error; 1519 1377 ··· 1531 1391 void mt7996_unregister_device(struct mt7996_dev *dev) 1532 1392 { 1533 1393 cancel_work_sync(&dev->wed_rro.work); 1534 - mt7996_unregister_phy(mt7996_phy3(dev), MT_BAND2); 1535 - mt7996_unregister_phy(mt7996_phy2(dev), MT_BAND1); 1394 + mt7996_unregister_phy(mt7996_phy3(dev)); 1395 + mt7996_unregister_phy(mt7996_phy2(dev)); 1536 1396 mt7996_unregister_thermal(&dev->phy); 1537 1397 mt7996_coredump_unregister(dev); 1538 1398 mt76_unregister_device(&dev->mt76);
+29 -28
drivers/net/wireless/mediatek/mt76/mt7996/mac.c
··· 72 72 if (!sta->vif) 73 73 return NULL; 74 74 75 - return &sta->vif->sta.wcid; 75 + return &sta->vif->deflink.sta.wcid; 76 76 } 77 77 78 78 bool mt7996_mac_wtbl_update(struct mt7996_dev *dev, int idx, u32 mask) ··· 182 182 rssi[3] = to_rssi(GENMASK(31, 14), val); 183 183 184 184 msta->ack_signal = 185 - mt76_rx_signal(msta->vif->phy->mt76->antenna_mask, rssi); 185 + mt76_rx_signal(msta->vif->deflink.phy->mt76->antenna_mask, rssi); 186 186 187 187 ewma_avg_signal_add(&msta->avg_ack_signal, -msta->ack_signal); 188 188 } ··· 196 196 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 197 197 u32 addr; 198 198 199 - addr = mt7996_mac_wtbl_lmac_addr(dev, mvif->sta.wcid.idx, 5); 199 + addr = mt7996_mac_wtbl_lmac_addr(dev, mvif->deflink.sta.wcid.idx, 5); 200 200 if (enable) 201 201 mt76_set(dev, addr, BIT(5)); 202 202 else ··· 478 478 479 479 if (status->wcid) { 480 480 msta = container_of(status->wcid, struct mt7996_sta, wcid); 481 - spin_lock_bh(&dev->mt76.sta_poll_lock); 482 - if (list_empty(&msta->wcid.poll_list)) 483 - list_add_tail(&msta->wcid.poll_list, 484 - &dev->mt76.sta_poll_list); 485 - spin_unlock_bh(&dev->mt76.sta_poll_lock); 481 + mt76_wcid_add_poll(&dev->mt76, &msta->wcid); 486 482 } 487 483 488 484 status->freq = mphy->chandef.chan->center_freq; ··· 675 679 if (ieee80211_has_a4(fc) && is_mesh && status->amsdu) 676 680 *qos &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT; 677 681 } 682 + skb_set_mac_header(skb, (unsigned char *)hdr - skb->data); 678 683 } else { 679 684 status->flag |= RX_FLAG_8023; 680 685 mt7996_wed_check_ppe(dev, &dev->mt76.q_rx[q], msta, skb, 681 686 *info); 682 687 } 683 688 684 - if (rxv && mode >= MT_PHY_TYPE_HE_SU && !(status->flag & RX_FLAG_8023)) 685 - mt76_connac3_mac_decode_he_radiotap(skb, rxv, mode); 689 + if (rxv && !(status->flag & RX_FLAG_8023)) { 690 + switch (status->encoding) { 691 + case RX_ENC_EHT: 692 + mt76_connac3_mac_decode_eht_radiotap(skb, rxv, mode); 693 + break; 694 + case RX_ENC_HE: 695 + mt76_connac3_mac_decode_he_radiotap(skb, rxv, mode); 696 + break; 697 + default: 698 + break; 699 + } 700 + } 686 701 687 702 if (!status->wcid || !ieee80211_is_data_qos(fc) || hw_aggr) 688 703 return 0; ··· 826 819 struct ieee80211_key_conf *key, int pid, 827 820 enum mt76_txq_id qid, u32 changed) 828 821 { 822 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 829 823 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 830 824 struct ieee80211_vif *vif = info->control.vif; 831 825 u8 band_idx = (info->hw_queue & MT_TX_HW_QUEUE_PHY) >> 2; 832 826 u8 p_fmt, q_idx, omac_idx = 0, wmm_idx = 0; 833 827 bool is_8023 = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP; 834 - struct mt76_vif *mvif; 828 + struct mt76_vif_link *mvif; 835 829 u16 tx_count = 15; 836 830 u32 val; 837 831 bool inband_disc = !!(changed & (BSS_CHANGED_UNSOL_BCAST_PROBE_RESP | ··· 840 832 bool beacon = !!(changed & (BSS_CHANGED_BEACON | 841 833 BSS_CHANGED_BEACON_ENABLED)) && (!inband_disc); 842 834 843 - mvif = vif ? (struct mt76_vif *)vif->drv_priv : NULL; 835 + mvif = vif ? (struct mt76_vif_link *)vif->drv_priv : NULL; 844 836 if (mvif) { 845 837 omac_idx = mvif->omac_idx; 846 838 wmm_idx = mvif->wmm_idx; ··· 894 886 val = MT_TXD6_DIS_MAT | MT_TXD6_DAS; 895 887 if (is_mt7996(&dev->mt76)) 896 888 val |= FIELD_PREP(MT_TXD6_MSDU_CNT, 1); 897 - else 889 + else if (is_8023 || !ieee80211_is_mgmt(hdr->frame_control)) 898 890 val |= FIELD_PREP(MT_TXD6_MSDU_CNT_V2, 1); 891 + 899 892 txwi[6] = cpu_to_le32(val); 900 893 txwi[7] = 0; 901 894 ··· 906 897 mt7996_mac_write_txwi_80211(dev, txwi, skb, key); 907 898 908 899 if (txwi[1] & cpu_to_le32(MT_TXD1_FIXED_RATE)) { 909 - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 910 900 bool mcast = ieee80211_is_data(hdr->frame_control) && 911 901 is_multicast_ether_addr(hdr->addr1); 912 902 u8 idx = MT7996_BASIC_RATES_TBL; ··· 985 977 if (vif) { 986 978 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 987 979 988 - txp->fw.bss_idx = mvif->mt76.idx; 980 + txp->fw.bss_idx = mvif->deflink.mt76.idx; 989 981 } 990 982 991 983 txp->fw.token = cpu_to_le16(id); ··· 1146 1138 continue; 1147 1139 1148 1140 msta = container_of(wcid, struct mt7996_sta, wcid); 1149 - spin_lock_bh(&mdev->sta_poll_lock); 1150 - if (list_empty(&msta->wcid.poll_list)) 1151 - list_add_tail(&msta->wcid.poll_list, 1152 - &mdev->sta_poll_list); 1153 - spin_unlock_bh(&mdev->sta_poll_lock); 1141 + mt76_wcid_add_poll(&dev->mt76, &msta->wcid); 1154 1142 continue; 1155 1143 } else if (info & MT_TXFREE_INFO_HEADER) { 1156 1144 u32 tx_retries = 0, tx_failed = 0; ··· 1372 1368 if (!wcid->sta) 1373 1369 goto out; 1374 1370 1375 - spin_lock_bh(&dev->mt76.sta_poll_lock); 1376 - if (list_empty(&msta->wcid.poll_list)) 1377 - list_add_tail(&msta->wcid.poll_list, &dev->mt76.sta_poll_list); 1378 - spin_unlock_bh(&dev->mt76.sta_poll_lock); 1371 + mt76_wcid_add_poll(&dev->mt76, &msta->wcid); 1379 1372 1380 1373 out: 1381 1374 rcu_read_unlock(); ··· 1594 1593 case NL80211_IFTYPE_MESH_POINT: 1595 1594 case NL80211_IFTYPE_ADHOC: 1596 1595 case NL80211_IFTYPE_AP: 1597 - mt7996_mcu_add_beacon(hw, vif, vif->bss_conf.enable_beacon); 1596 + mt7996_mcu_add_beacon(hw, vif, &vif->bss_conf); 1598 1597 break; 1599 1598 default: 1600 1599 break; ··· 1739 1738 ret = mt7996_txbf_init(dev); 1740 1739 1741 1740 if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) { 1742 - ret = mt7996_run(dev->mphy.hw); 1741 + ret = mt7996_run(&dev->phy); 1743 1742 if (ret) 1744 1743 goto out; 1745 1744 } 1746 1745 1747 1746 if (phy2 && test_bit(MT76_STATE_RUNNING, &phy2->mt76->state)) { 1748 - ret = mt7996_run(phy2->mt76->hw); 1747 + ret = mt7996_run(phy2); 1749 1748 if (ret) 1750 1749 goto out; 1751 1750 } 1752 1751 1753 1752 if (phy3 && test_bit(MT76_STATE_RUNNING, &phy3->mt76->state)) { 1754 - ret = mt7996_run(phy3->mt76->hw); 1753 + ret = mt7996_run(phy3); 1755 1754 if (ret) 1756 1755 goto out; 1757 1756 }
+536 -367
drivers/net/wireless/mediatek/mt76/mt7996/main.c
··· 7 7 #include "mcu.h" 8 8 #include "mac.h" 9 9 10 - static bool mt7996_dev_running(struct mt7996_dev *dev) 10 + int mt7996_run(struct mt7996_phy *phy) 11 11 { 12 - struct mt7996_phy *phy; 13 - 14 - if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) 15 - return true; 16 - 17 - phy = mt7996_phy2(dev); 18 - if (phy && test_bit(MT76_STATE_RUNNING, &phy->mt76->state)) 19 - return true; 20 - 21 - phy = mt7996_phy3(dev); 22 - 23 - return phy && test_bit(MT76_STATE_RUNNING, &phy->mt76->state); 24 - } 25 - 26 - int mt7996_run(struct ieee80211_hw *hw) 27 - { 28 - struct mt7996_dev *dev = mt7996_hw_dev(hw); 29 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 30 - bool running; 12 + struct mt7996_dev *dev = phy->dev; 31 13 int ret; 32 - 33 - running = mt7996_dev_running(dev); 34 - if (!running) { 35 - ret = mt7996_mcu_set_hdr_trans(dev, true); 36 - if (ret) 37 - goto out; 38 - 39 - if (is_mt7992(&dev->mt76)) { 40 - u8 queue = mt76_connac_lmac_mapping(IEEE80211_AC_VI); 41 - 42 - ret = mt7996_mcu_cp_support(dev, queue); 43 - if (ret) 44 - goto out; 45 - } 46 - } 47 14 48 15 mt7996_mac_enable_nf(dev, phy->mt76->band_idx); 49 16 50 17 ret = mt7996_mcu_set_rts_thresh(phy, 0x92b); 51 18 if (ret) 52 - goto out; 19 + return ret; 53 20 54 21 ret = mt7996_mcu_set_radio_en(phy, true); 55 22 if (ret) 56 - goto out; 23 + return ret; 57 24 58 25 ret = mt7996_mcu_set_chan_info(phy, UNI_CHANNEL_RX_PATH); 59 26 if (ret) 60 - goto out; 27 + return ret; 61 28 62 29 ret = mt7996_mcu_set_thermal_throttling(phy, MT7996_THERMAL_THROTTLE_MAX); 63 30 if (ret) 64 - goto out; 31 + return ret; 65 32 66 33 ret = mt7996_mcu_set_thermal_protect(phy, true); 67 34 if (ret) 68 - goto out; 35 + return ret; 69 36 70 37 set_bit(MT76_STATE_RUNNING, &phy->mt76->state); 71 38 72 - ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work, 39 + ieee80211_queue_delayed_work(dev->mphy.hw, &phy->mt76->mac_work, 73 40 MT7996_WATCHDOG_TIME); 74 41 75 - if (!running) 42 + if (!phy->counter_reset) { 76 43 mt7996_mac_reset_counters(phy); 44 + phy->counter_reset = true; 45 + } 77 46 78 - out: 79 - return ret; 47 + return 0; 80 48 } 81 49 82 50 static int mt7996_start(struct ieee80211_hw *hw) ··· 55 87 flush_work(&dev->init_work); 56 88 57 89 mutex_lock(&dev->mt76.mutex); 58 - ret = mt7996_run(hw); 90 + ret = mt7996_mcu_set_hdr_trans(dev, true); 91 + if (!ret && is_mt7992(&dev->mt76)) { 92 + u8 queue = mt76_connac_lmac_mapping(IEEE80211_AC_VI); 93 + 94 + ret = mt7996_mcu_cp_support(dev, queue); 95 + } 59 96 mutex_unlock(&dev->mt76.mutex); 60 97 61 98 return ret; 62 99 } 63 100 64 - static void mt7996_stop(struct ieee80211_hw *hw, bool suspend) 101 + static void mt7996_stop_phy(struct mt7996_phy *phy) 65 102 { 66 - struct mt7996_dev *dev = mt7996_hw_dev(hw); 67 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 103 + struct mt7996_dev *dev = phy->dev; 104 + 105 + if (!phy || !test_bit(MT76_STATE_RUNNING, &phy->mt76->state)) 106 + return; 68 107 69 108 cancel_delayed_work_sync(&phy->mt76->mac_work); 70 109 ··· 82 107 clear_bit(MT76_STATE_RUNNING, &phy->mt76->state); 83 108 84 109 mutex_unlock(&dev->mt76.mutex); 110 + } 111 + 112 + static void mt7996_stop(struct ieee80211_hw *hw, bool suspend) 113 + { 85 114 } 86 115 87 116 static inline int get_free_idx(u32 mask, u8 start, u8 end) ··· 136 157 return -1; 137 158 } 138 159 139 - static void mt7996_init_bitrate_mask(struct ieee80211_vif *vif) 160 + static void 161 + mt7996_init_bitrate_mask(struct ieee80211_vif *vif, struct mt7996_vif_link *mlink) 140 162 { 141 - struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 142 163 int i; 143 164 144 - for (i = 0; i < ARRAY_SIZE(mvif->bitrate_mask.control); i++) { 145 - mvif->bitrate_mask.control[i].gi = NL80211_TXRATE_DEFAULT_GI; 146 - mvif->bitrate_mask.control[i].he_gi = 0xff; 147 - mvif->bitrate_mask.control[i].he_ltf = 0xff; 148 - mvif->bitrate_mask.control[i].legacy = GENMASK(31, 0); 149 - memset(mvif->bitrate_mask.control[i].ht_mcs, 0xff, 150 - sizeof(mvif->bitrate_mask.control[i].ht_mcs)); 151 - memset(mvif->bitrate_mask.control[i].vht_mcs, 0xff, 152 - sizeof(mvif->bitrate_mask.control[i].vht_mcs)); 153 - memset(mvif->bitrate_mask.control[i].he_mcs, 0xff, 154 - sizeof(mvif->bitrate_mask.control[i].he_mcs)); 165 + for (i = 0; i < ARRAY_SIZE(mlink->bitrate_mask.control); i++) { 166 + mlink->bitrate_mask.control[i].gi = NL80211_TXRATE_DEFAULT_GI; 167 + mlink->bitrate_mask.control[i].he_gi = 0xff; 168 + mlink->bitrate_mask.control[i].he_ltf = 0xff; 169 + mlink->bitrate_mask.control[i].legacy = GENMASK(31, 0); 170 + memset(mlink->bitrate_mask.control[i].ht_mcs, 0xff, 171 + sizeof(mlink->bitrate_mask.control[i].ht_mcs)); 172 + memset(mlink->bitrate_mask.control[i].vht_mcs, 0xff, 173 + sizeof(mlink->bitrate_mask.control[i].vht_mcs)); 174 + memset(mlink->bitrate_mask.control[i].he_mcs, 0xff, 175 + sizeof(mlink->bitrate_mask.control[i].he_mcs)); 155 176 } 156 177 } 157 178 158 - static int mt7996_add_interface(struct ieee80211_hw *hw, 159 - struct ieee80211_vif *vif) 179 + static int 180 + mt7996_set_hw_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 181 + struct ieee80211_vif *vif, struct ieee80211_sta *sta, 182 + struct mt7996_vif_link *mlink, struct ieee80211_key_conf *key) 160 183 { 161 - struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 162 184 struct mt7996_dev *dev = mt7996_hw_dev(hw); 163 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 164 - struct mt76_txq *mtxq; 165 - u8 band_idx = phy->mt76->band_idx; 166 - int idx, ret = 0; 185 + struct mt7996_sta *msta = sta ? (struct mt7996_sta *)sta->drv_priv : 186 + &mlink->sta; 187 + struct mt76_wcid *wcid = &msta->wcid; 188 + u8 *wcid_keyidx = &wcid->hw_key_idx; 189 + struct mt7996_phy *phy; 190 + int idx = key->keyidx; 167 191 168 - mutex_lock(&dev->mt76.mutex); 192 + phy = mt7996_vif_link_phy(mlink); 193 + if (!phy) 194 + return -EINVAL; 169 195 170 - if (vif->type == NL80211_IFTYPE_MONITOR && 171 - is_zero_ether_addr(vif->addr)) 172 - phy->monitor_vif = vif; 196 + if (sta && !wcid->sta) 197 + return -EOPNOTSUPP; 173 198 174 - mvif->mt76.idx = __ffs64(~dev->mt76.vif_mask); 175 - if (mvif->mt76.idx >= mt7996_max_interface_num(dev)) { 176 - ret = -ENOSPC; 177 - goto out; 199 + switch (key->cipher) { 200 + case WLAN_CIPHER_SUITE_AES_CMAC: 201 + case WLAN_CIPHER_SUITE_BIP_CMAC_256: 202 + case WLAN_CIPHER_SUITE_BIP_GMAC_128: 203 + case WLAN_CIPHER_SUITE_BIP_GMAC_256: 204 + if (key->keyidx == 6 || key->keyidx == 7) { 205 + wcid_keyidx = &wcid->hw_key_idx2; 206 + key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE; 207 + } 208 + break; 209 + default: 210 + break; 178 211 } 212 + 213 + if (cmd == SET_KEY && !sta && !mlink->mt76.cipher) { 214 + mlink->mt76.cipher = mt76_connac_mcu_get_cipher(key->cipher); 215 + mt7996_mcu_add_bss_info(phy, vif, &vif->bss_conf, &mlink->mt76, true); 216 + } 217 + 218 + if (cmd == SET_KEY) { 219 + *wcid_keyidx = idx; 220 + } else { 221 + if (idx == *wcid_keyidx) 222 + *wcid_keyidx = -1; 223 + return 0; 224 + } 225 + 226 + mt76_wcid_key_setup(&dev->mt76, wcid, key); 227 + 228 + if (key->keyidx == 6 || key->keyidx == 7) 229 + return mt7996_mcu_bcn_prot_enable(dev, vif, key); 230 + 231 + return mt7996_mcu_add_key(&dev->mt76, vif, key, 232 + MCU_WMWA_UNI_CMD(STA_REC_UPDATE), 233 + &msta->wcid, cmd); 234 + } 235 + 236 + static void 237 + mt7996_key_iter(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 238 + struct ieee80211_sta *sta, struct ieee80211_key_conf *key, 239 + void *data) 240 + { 241 + struct mt7996_vif_link *mlink = data; 242 + 243 + if (sta) 244 + return; 245 + 246 + WARN_ON(mt7996_set_hw_key(hw, SET_KEY, vif, NULL, mlink, key)); 247 + } 248 + 249 + int mt7996_vif_link_add(struct mt76_phy *mphy, struct ieee80211_vif *vif, 250 + struct ieee80211_bss_conf *link_conf, 251 + struct mt76_vif_link *mlink) 252 + { 253 + struct mt7996_vif_link *link = container_of(mlink, struct mt7996_vif_link, mt76); 254 + struct mt7996_phy *phy = mphy->priv; 255 + struct mt7996_dev *dev = phy->dev; 256 + u8 band_idx = phy->mt76->band_idx; 257 + struct mt76_txq *mtxq; 258 + int idx, ret; 259 + 260 + mlink->idx = __ffs64(~dev->mt76.vif_mask); 261 + if (mlink->idx >= mt7996_max_interface_num(dev)) 262 + return -ENOSPC; 179 263 180 264 idx = get_omac_idx(vif->type, phy->omac_mask); 181 - if (idx < 0) { 182 - ret = -ENOSPC; 183 - goto out; 184 - } 185 - mvif->mt76.omac_idx = idx; 186 - mvif->phy = phy; 187 - mvif->mt76.band_idx = band_idx; 188 - mvif->mt76.wmm_idx = vif->type == NL80211_IFTYPE_AP ? 0 : 3; 265 + if (idx < 0) 266 + return -ENOSPC; 189 267 190 - ret = mt7996_mcu_add_dev_info(phy, vif, true); 268 + link->phy = phy; 269 + mlink->omac_idx = idx; 270 + mlink->band_idx = band_idx; 271 + mlink->wmm_idx = vif->type == NL80211_IFTYPE_AP ? 0 : 3; 272 + mlink->wcid = &link->sta.wcid; 273 + 274 + ret = mt7996_mcu_add_dev_info(phy, vif, link_conf, mlink, true); 191 275 if (ret) 192 - goto out; 276 + return ret; 193 277 194 - dev->mt76.vif_mask |= BIT_ULL(mvif->mt76.idx); 195 - phy->omac_mask |= BIT_ULL(mvif->mt76.omac_idx); 278 + dev->mt76.vif_mask |= BIT_ULL(mlink->idx); 279 + phy->omac_mask |= BIT_ULL(mlink->omac_idx); 196 280 197 - idx = MT7996_WTBL_RESERVED - mvif->mt76.idx; 281 + idx = MT7996_WTBL_RESERVED - mlink->idx; 198 282 199 - INIT_LIST_HEAD(&mvif->sta.rc_list); 200 - INIT_LIST_HEAD(&mvif->sta.wcid.poll_list); 201 - mvif->sta.wcid.idx = idx; 202 - mvif->sta.wcid.phy_idx = band_idx; 203 - mvif->sta.wcid.hw_key_idx = -1; 204 - mvif->sta.wcid.tx_info |= MT_WCID_TX_INFO_SET; 205 - mt76_wcid_init(&mvif->sta.wcid); 283 + INIT_LIST_HEAD(&link->sta.rc_list); 284 + link->sta.wcid.idx = idx; 285 + link->sta.wcid.tx_info |= MT_WCID_TX_INFO_SET; 286 + mt76_wcid_init(&link->sta.wcid, band_idx); 206 287 207 288 mt7996_mac_wtbl_update(dev, idx, 208 289 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); ··· 273 234 } 274 235 275 236 if (vif->type != NL80211_IFTYPE_AP && 276 - (!mvif->mt76.omac_idx || mvif->mt76.omac_idx > 3)) 237 + (!mlink->omac_idx || mlink->omac_idx > 3)) 277 238 vif->offload_flags = 0; 278 - vif->offload_flags |= IEEE80211_OFFLOAD_ENCAP_4ADDR; 279 239 280 240 if (phy->mt76->chandef.chan->band != NL80211_BAND_2GHZ) 281 - mvif->mt76.basic_rates_idx = MT7996_BASIC_RATES_TBL + 4; 241 + mlink->basic_rates_idx = MT7996_BASIC_RATES_TBL + 4; 282 242 else 283 - mvif->mt76.basic_rates_idx = MT7996_BASIC_RATES_TBL; 243 + mlink->basic_rates_idx = MT7996_BASIC_RATES_TBL; 284 244 285 - mt7996_init_bitrate_mask(vif); 245 + mt7996_init_bitrate_mask(vif, link); 286 246 287 - mt7996_mcu_add_bss_info(phy, vif, true); 247 + mt7996_mcu_add_bss_info(phy, vif, link_conf, mlink, true); 288 248 /* defer the first STA_REC of BMC entry to BSS_CHANGED_BSSID for STA 289 249 * interface, since firmware only records BSSID when the entry is new 290 250 */ 291 251 if (vif->type != NL80211_IFTYPE_STATION) 292 - mt7996_mcu_add_sta(dev, vif, NULL, true, true); 293 - rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid); 252 + mt7996_mcu_add_sta(dev, vif, mlink, NULL, CONN_STATE_PORT_SECURE, true); 253 + rcu_assign_pointer(dev->mt76.wcid[idx], &link->sta.wcid); 294 254 295 - out: 296 - mutex_unlock(&dev->mt76.mutex); 255 + ieee80211_iter_keys(mphy->hw, vif, mt7996_key_iter, link); 297 256 298 - return ret; 257 + return 0; 299 258 } 300 259 301 - static void mt7996_remove_interface(struct ieee80211_hw *hw, 302 - struct ieee80211_vif *vif) 260 + void mt7996_vif_link_remove(struct mt76_phy *mphy, struct ieee80211_vif *vif, 261 + struct ieee80211_bss_conf *link_conf, 262 + struct mt76_vif_link *mlink) 303 263 { 304 - struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 305 - struct mt7996_sta *msta = &mvif->sta; 306 - struct mt7996_dev *dev = mt7996_hw_dev(hw); 307 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 308 - int idx = msta->wcid.idx; 264 + struct mt7996_vif_link *link = container_of(mlink, struct mt7996_vif_link, mt76); 265 + struct mt7996_phy *phy = mphy->priv; 266 + struct mt7996_dev *dev = phy->dev; 267 + struct mt7996_sta *msta; 268 + int idx; 309 269 310 - mt7996_mcu_add_sta(dev, vif, NULL, false, false); 311 - mt7996_mcu_add_bss_info(phy, vif, false); 270 + msta = &link->sta; 271 + idx = msta->wcid.idx; 272 + mt7996_mcu_add_sta(dev, vif, mlink, NULL, CONN_STATE_DISCONNECT, false); 273 + mt7996_mcu_add_bss_info(phy, vif, link_conf, mlink, false); 312 274 313 - if (vif == phy->monitor_vif) 314 - phy->monitor_vif = NULL; 315 - 316 - mt7996_mcu_add_dev_info(phy, vif, false); 275 + mt7996_mcu_add_dev_info(phy, vif, link_conf, mlink, false); 317 276 318 277 rcu_assign_pointer(dev->mt76.wcid[idx], NULL); 319 278 320 - mutex_lock(&dev->mt76.mutex); 321 - dev->mt76.vif_mask &= ~BIT_ULL(mvif->mt76.idx); 322 - phy->omac_mask &= ~BIT_ULL(mvif->mt76.omac_idx); 323 - mutex_unlock(&dev->mt76.mutex); 279 + dev->mt76.vif_mask &= ~BIT_ULL(mlink->idx); 280 + phy->omac_mask &= ~BIT_ULL(mlink->omac_idx); 324 281 325 282 spin_lock_bh(&dev->mt76.sta_poll_lock); 326 283 if (!list_empty(&msta->wcid.poll_list)) ··· 324 289 spin_unlock_bh(&dev->mt76.sta_poll_lock); 325 290 326 291 mt76_wcid_cleanup(&dev->mt76, &msta->wcid); 292 + } 293 + 294 + static void mt7996_phy_set_rxfilter(struct mt7996_phy *phy) 295 + { 296 + struct mt7996_dev *dev = phy->dev; 297 + u32 ctl_flags = MT_WF_RFCR1_DROP_ACK | 298 + MT_WF_RFCR1_DROP_BF_POLL | 299 + MT_WF_RFCR1_DROP_BA | 300 + MT_WF_RFCR1_DROP_CFEND | 301 + MT_WF_RFCR1_DROP_CFACK; 302 + u32 filter = phy->rxfilter; 303 + 304 + if (filter & MT_WF_RFCR_DROP_OTHER_UC) { 305 + filter |= MT_WF_RFCR_DROP_CTS | 306 + MT_WF_RFCR_DROP_RTS | 307 + MT_WF_RFCR_DROP_CTL_RSV | 308 + MT_WF_RFCR_DROP_FCSFAIL; 309 + } 310 + 311 + mt76_wr(dev, MT_WF_RFCR(phy->mt76->band_idx), filter); 312 + if (filter & MT_WF_RFCR_DROP_CTL_RSV) 313 + mt76_set(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags); 314 + else 315 + mt76_clear(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags); 316 + } 317 + 318 + static void mt7996_set_monitor(struct mt7996_phy *phy, bool enabled) 319 + { 320 + struct mt7996_dev *dev = phy->dev; 321 + 322 + if (!phy) 323 + return; 324 + 325 + if (enabled == !(phy->rxfilter & MT_WF_RFCR_DROP_OTHER_UC)) 326 + return; 327 + 328 + if (!enabled) 329 + phy->rxfilter |= MT_WF_RFCR_DROP_OTHER_UC; 330 + else 331 + phy->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_UC; 332 + 333 + mt76_rmw_field(dev, MT_DMA_DCR0(phy->mt76->band_idx), 334 + MT_DMA_DCR0_RXD_G5_EN, enabled); 335 + mt7996_phy_set_rxfilter(phy); 336 + mt7996_mcu_set_sniffer_mode(phy, enabled); 337 + } 338 + 339 + static int mt7996_add_interface(struct ieee80211_hw *hw, 340 + struct ieee80211_vif *vif) 341 + { 342 + struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 343 + struct wireless_dev *wdev = ieee80211_vif_to_wdev(vif); 344 + struct mt7996_dev *dev = mt7996_hw_dev(hw); 345 + int i, err = 0; 346 + 347 + mutex_lock(&dev->mt76.mutex); 348 + 349 + for (i = 0; i < MT7996_MAX_RADIOS; i++) { 350 + struct mt7996_phy *phy = dev->radio_phy[i]; 351 + 352 + if (!phy || !(wdev->radio_mask & BIT(i)) || 353 + test_bit(MT76_STATE_RUNNING, &phy->mt76->state)) 354 + continue; 355 + 356 + err = mt7996_run(phy); 357 + if (err) 358 + goto out; 359 + 360 + if (vif->type == NL80211_IFTYPE_MONITOR) 361 + mt7996_set_monitor(phy, true); 362 + } 363 + 364 + mt76_vif_init(vif, &mvif->mt76); 365 + 366 + vif->offload_flags |= IEEE80211_OFFLOAD_ENCAP_4ADDR; 367 + 368 + out: 369 + mutex_unlock(&dev->mt76.mutex); 370 + 371 + return err; 372 + } 373 + 374 + struct mt7996_radio_data { 375 + u32 active_mask; 376 + u32 monitor_mask; 377 + }; 378 + 379 + static void mt7996_remove_iter(void *data, u8 *mac, struct ieee80211_vif *vif) 380 + { 381 + struct wireless_dev *wdev = ieee80211_vif_to_wdev(vif); 382 + struct mt7996_radio_data *rdata = data; 383 + 384 + rdata->active_mask |= wdev->radio_mask; 385 + if (vif->type == NL80211_IFTYPE_MONITOR) 386 + rdata->monitor_mask |= wdev->radio_mask; 387 + } 388 + 389 + static void mt7996_remove_interface(struct ieee80211_hw *hw, 390 + struct ieee80211_vif *vif) 391 + { 392 + struct mt7996_dev *dev = mt7996_hw_dev(hw); 393 + struct mt7996_radio_data rdata = {}; 394 + int i; 395 + 396 + ieee80211_iterate_active_interfaces_mtx(hw, 0, mt7996_remove_iter, 397 + &rdata); 398 + mt76_vif_cleanup(&dev->mt76, vif); 399 + 400 + for (i = 0; i < MT7996_MAX_RADIOS; i++) { 401 + struct mt7996_phy *phy = dev->radio_phy[i]; 402 + 403 + if (!phy) 404 + continue; 405 + if (!(rdata.monitor_mask & BIT(i))) 406 + mt7996_set_monitor(phy, false); 407 + if (!(rdata.active_mask & BIT(i))) 408 + mt7996_stop_phy(phy); 409 + } 327 410 } 328 411 329 412 int mt7996_set_channel(struct mt76_phy *mphy) ··· 454 301 goto out; 455 302 456 303 ret = mt7996_mcu_set_chan_info(phy, UNI_CHANNEL_RX_PATH); 304 + if (ret) 305 + goto out; 306 + 307 + ret = mt7996_mcu_set_txpower_sku(phy); 457 308 if (ret) 458 309 goto out; 459 310 ··· 479 322 struct ieee80211_key_conf *key) 480 323 { 481 324 struct mt7996_dev *dev = mt7996_hw_dev(hw); 482 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 483 325 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 484 - struct mt7996_sta *msta = sta ? (struct mt7996_sta *)sta->drv_priv : 485 - &mvif->sta; 486 - struct mt76_wcid *wcid = &msta->wcid; 487 - u8 *wcid_keyidx = &wcid->hw_key_idx; 488 - int idx = key->keyidx; 489 - int err = 0; 326 + struct mt7996_vif_link *mlink = &mvif->deflink; 327 + int err; 490 328 491 329 /* The hardware does not support per-STA RX GTK, fallback 492 330 * to software mode for these. ··· 506 354 case WLAN_CIPHER_SUITE_BIP_CMAC_256: 507 355 case WLAN_CIPHER_SUITE_BIP_GMAC_128: 508 356 case WLAN_CIPHER_SUITE_BIP_GMAC_256: 509 - if (key->keyidx == 6 || key->keyidx == 7) { 510 - wcid_keyidx = &wcid->hw_key_idx2; 511 - key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE; 357 + if (key->keyidx == 6 || key->keyidx == 7) 512 358 break; 513 - } 514 359 fallthrough; 515 360 case WLAN_CIPHER_SUITE_WEP40: 516 361 case WLAN_CIPHER_SUITE_WEP104: ··· 515 366 return -EOPNOTSUPP; 516 367 } 517 368 369 + if (!mt7996_vif_link_phy(mlink)) 370 + return 0; /* defer until after link add */ 371 + 518 372 mutex_lock(&dev->mt76.mutex); 519 - 520 - if (cmd == SET_KEY && !sta && !mvif->mt76.cipher) { 521 - mvif->mt76.cipher = mt76_connac_mcu_get_cipher(key->cipher); 522 - mt7996_mcu_add_bss_info(phy, vif, true); 523 - } 524 - 525 - if (cmd == SET_KEY) { 526 - *wcid_keyidx = idx; 527 - } else { 528 - if (idx == *wcid_keyidx) 529 - *wcid_keyidx = -1; 530 - goto out; 531 - } 532 - 533 - mt76_wcid_key_setup(&dev->mt76, wcid, key); 534 - 535 - if (key->keyidx == 6 || key->keyidx == 7) 536 - err = mt7996_mcu_bcn_prot_enable(dev, vif, key); 537 - else 538 - err = mt7996_mcu_add_key(&dev->mt76, vif, key, 539 - MCU_WMWA_UNI_CMD(STA_REC_UPDATE), 540 - &msta->wcid, cmd); 541 - out: 373 + err = mt7996_set_hw_key(hw, cmd, vif, sta, mlink, key); 542 374 mutex_unlock(&dev->mt76.mutex); 543 375 544 376 return err; ··· 527 397 528 398 static int mt7996_config(struct ieee80211_hw *hw, u32 changed) 529 399 { 530 - struct mt7996_dev *dev = mt7996_hw_dev(hw); 531 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 532 - int ret; 533 - 534 - if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { 535 - ret = mt76_update_channel(phy->mt76); 536 - if (ret) 537 - return ret; 538 - } 539 - 540 - if (changed & (IEEE80211_CONF_CHANGE_POWER | 541 - IEEE80211_CONF_CHANGE_CHANNEL)) { 542 - ret = mt7996_mcu_set_txpower_sku(phy); 543 - if (ret) 544 - return ret; 545 - } 546 - 547 - mutex_lock(&dev->mt76.mutex); 548 - 549 - if (changed & IEEE80211_CONF_CHANGE_MONITOR) { 550 - bool enabled = !!(hw->conf.flags & IEEE80211_CONF_MONITOR); 551 - 552 - if (!enabled) 553 - phy->rxfilter |= MT_WF_RFCR_DROP_OTHER_UC; 554 - else 555 - phy->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_UC; 556 - 557 - mt76_rmw_field(dev, MT_DMA_DCR0(phy->mt76->band_idx), 558 - MT_DMA_DCR0_RXD_G5_EN, enabled); 559 - mt76_wr(dev, MT_WF_RFCR(phy->mt76->band_idx), phy->rxfilter); 560 - } 561 - 562 - mutex_unlock(&dev->mt76.mutex); 563 - 564 400 return 0; 565 401 } 566 402 ··· 535 439 unsigned int link_id, u16 queue, 536 440 const struct ieee80211_tx_queue_params *params) 537 441 { 538 - struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 442 + struct mt7996_dev *dev = mt7996_hw_dev(hw); 443 + struct mt7996_vif_link *mlink = mt7996_vif_link(dev, vif, link_id); 539 444 static const u8 mq_to_aci[] = { 540 445 [IEEE80211_AC_VO] = 3, 541 446 [IEEE80211_AC_VI] = 2, ··· 545 448 }; 546 449 547 450 /* firmware uses access class index */ 548 - mvif->queue_params[mq_to_aci[queue]] = *params; 451 + mlink->queue_params[mq_to_aci[queue]] = *params; 549 452 /* no need to update right away, we'll get BSS_CHANGED_QOS */ 550 453 551 454 return 0; ··· 557 460 u64 multicast) 558 461 { 559 462 struct mt7996_dev *dev = mt7996_hw_dev(hw); 560 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 561 - u32 ctl_flags = MT_WF_RFCR1_DROP_ACK | 562 - MT_WF_RFCR1_DROP_BF_POLL | 563 - MT_WF_RFCR1_DROP_BA | 564 - MT_WF_RFCR1_DROP_CFEND | 565 - MT_WF_RFCR1_DROP_CFACK; 463 + struct mt7996_phy *phy; 464 + u32 filter_mask = 0, filter_set = 0; 566 465 u32 flags = 0; 567 466 568 - #define MT76_FILTER(_flag, _hw) do { \ 569 - flags |= *total_flags & FIF_##_flag; \ 570 - phy->rxfilter &= ~(_hw); \ 571 - phy->rxfilter |= !(flags & FIF_##_flag) * (_hw); \ 467 + #define MT76_FILTER(_flag, _hw) do { \ 468 + flags |= *total_flags & FIF_##_flag; \ 469 + filter_mask |= (_hw); \ 470 + filter_set |= !(flags & FIF_##_flag) * (_hw); \ 572 471 } while (0) 573 472 574 473 mutex_lock(&dev->mt76.mutex); 575 - 576 - phy->rxfilter &= ~(MT_WF_RFCR_DROP_OTHER_BSS | 577 - MT_WF_RFCR_DROP_OTHER_BEACON | 578 - MT_WF_RFCR_DROP_FRAME_REPORT | 579 - MT_WF_RFCR_DROP_PROBEREQ | 580 - MT_WF_RFCR_DROP_MCAST_FILTERED | 581 - MT_WF_RFCR_DROP_MCAST | 582 - MT_WF_RFCR_DROP_BCAST | 583 - MT_WF_RFCR_DROP_DUPLICATE | 584 - MT_WF_RFCR_DROP_A2_BSSID | 585 - MT_WF_RFCR_DROP_UNWANTED_CTL | 586 - MT_WF_RFCR_DROP_STBC_MULTI); 587 474 588 475 MT76_FILTER(OTHER_BSS, MT_WF_RFCR_DROP_OTHER_TIM | 589 476 MT_WF_RFCR_DROP_A3_MAC | ··· 577 496 578 497 MT76_FILTER(CONTROL, MT_WF_RFCR_DROP_CTS | 579 498 MT_WF_RFCR_DROP_RTS | 580 - MT_WF_RFCR_DROP_CTL_RSV | 581 - MT_WF_RFCR_DROP_NDPA); 499 + MT_WF_RFCR_DROP_CTL_RSV); 582 500 583 501 *total_flags = flags; 584 - mt76_wr(dev, MT_WF_RFCR(phy->mt76->band_idx), phy->rxfilter); 585 502 586 - if (*total_flags & FIF_CONTROL) 587 - mt76_clear(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags); 588 - else 589 - mt76_set(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags); 503 + mt7996_for_each_phy(dev, phy) { 504 + phy->rxfilter &= ~(MT_WF_RFCR_DROP_OTHER_BSS | 505 + MT_WF_RFCR_DROP_OTHER_BEACON | 506 + MT_WF_RFCR_DROP_FRAME_REPORT | 507 + MT_WF_RFCR_DROP_PROBEREQ | 508 + MT_WF_RFCR_DROP_MCAST_FILTERED | 509 + MT_WF_RFCR_DROP_MCAST | 510 + MT_WF_RFCR_DROP_BCAST | 511 + MT_WF_RFCR_DROP_DUPLICATE | 512 + MT_WF_RFCR_DROP_A2_BSSID | 513 + MT_WF_RFCR_DROP_UNWANTED_CTL | 514 + MT_WF_RFCR_DROP_STBC_MULTI | 515 + filter_mask); 516 + phy->rxfilter |= filter_set; 517 + mt7996_phy_set_rxfilter(phy); 518 + } 590 519 591 520 mutex_unlock(&dev->mt76.mutex); 592 521 } 593 522 594 - static void 595 - mt7996_update_bss_color(struct ieee80211_hw *hw, 596 - struct ieee80211_vif *vif, 597 - struct cfg80211_he_bss_color *bss_color) 598 - { 599 - struct mt7996_dev *dev = mt7996_hw_dev(hw); 600 - 601 - switch (vif->type) { 602 - case NL80211_IFTYPE_AP: { 603 - struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 604 - 605 - if (mvif->mt76.omac_idx > HW_BSSID_MAX) 606 - return; 607 - fallthrough; 608 - } 609 - case NL80211_IFTYPE_STATION: 610 - mt7996_mcu_update_bss_color(dev, vif, bss_color); 611 - break; 612 - default: 613 - break; 614 - } 615 - } 616 - 617 523 static u8 618 - mt7996_get_rates_table(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 524 + mt7996_get_rates_table(struct mt7996_phy *phy, struct ieee80211_bss_conf *conf, 619 525 bool beacon, bool mcast) 620 526 { 621 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 622 - struct mt76_phy *mphy = hw->priv; 527 + struct mt7996_dev *dev = phy->dev; 528 + struct mt76_vif_link *mvif = mt76_vif_conf_link(&dev->mt76, conf->vif, conf); 623 529 u16 rate; 624 530 u8 i, idx; 625 531 626 - rate = mt76_connac2_mac_tx_rate_val(mphy, vif, beacon, mcast); 532 + rate = mt76_connac2_mac_tx_rate_val(phy->mt76, conf, beacon, mcast); 627 533 628 534 if (beacon) { 629 - struct mt7996_phy *phy = mphy->priv; 630 - 631 535 /* odd index for driver, even index for firmware */ 632 536 idx = MT7996_BEACON_RATES_TBL + 2 * phy->mt76->band_idx; 633 537 if (phy->beacon_rate != rate) ··· 635 569 { 636 570 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 637 571 struct mt7996_dev *dev = mt7996_hw_dev(hw); 638 - u8 band = mvif->mt76.band_idx; 572 + u8 band = mvif->deflink.mt76.band_idx; 639 573 u32 *mu; 640 574 641 575 mu = (u32 *)info->mu_group.membership; ··· 654 588 struct ieee80211_bss_conf *info, 655 589 u64 changed) 656 590 { 657 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 658 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 659 591 struct mt7996_dev *dev = mt7996_hw_dev(hw); 592 + struct mt76_vif_link *mvif; 593 + struct mt7996_phy *phy; 594 + struct mt76_phy *mphy; 660 595 661 596 mutex_lock(&dev->mt76.mutex); 597 + 598 + mvif = mt76_vif_conf_link(&dev->mt76, vif, info); 599 + if (!mvif) 600 + goto out; 601 + 602 + mphy = mt76_vif_link_phy(mvif); 603 + if (!mphy) 604 + goto out; 605 + 606 + phy = mphy->priv; 662 607 663 608 /* station mode uses BSSID to map the wlan entry to a peer, 664 609 * and then peer references bss_info_rfch to set bandwidth cap. ··· 677 600 if ((changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid)) || 678 601 (changed & BSS_CHANGED_ASSOC && vif->cfg.assoc) || 679 602 (changed & BSS_CHANGED_BEACON_ENABLED && info->enable_beacon)) { 680 - mt7996_mcu_add_bss_info(phy, vif, true); 681 - mt7996_mcu_add_sta(dev, vif, NULL, true, 603 + mt7996_mcu_add_bss_info(phy, vif, info, mvif, true); 604 + mt7996_mcu_add_sta(dev, vif, mvif, NULL, CONN_STATE_PORT_SECURE, 682 605 !!(changed & BSS_CHANGED_BSSID)); 683 606 } 684 607 ··· 690 613 691 614 if (slottime != phy->slottime) { 692 615 phy->slottime = slottime; 693 - mt7996_mcu_set_timing(phy, vif); 616 + mt7996_mcu_set_timing(phy, vif, info); 694 617 } 695 618 } 696 619 697 620 if (changed & BSS_CHANGED_MCAST_RATE) 698 621 mvif->mcast_rates_idx = 699 - mt7996_get_rates_table(hw, vif, false, true); 622 + mt7996_get_rates_table(phy, info, false, true); 700 623 701 624 if (changed & BSS_CHANGED_BASIC_RATES) 702 625 mvif->basic_rates_idx = 703 - mt7996_get_rates_table(hw, vif, false, false); 626 + mt7996_get_rates_table(phy, info, false, false); 704 627 705 628 /* ensure that enable txcmd_mode after bss_info */ 706 629 if (changed & (BSS_CHANGED_QOS | BSS_CHANGED_BEACON_ENABLED)) 707 - mt7996_mcu_set_tx(dev, vif); 630 + mt7996_mcu_set_tx(dev, vif, info); 708 631 709 632 if (changed & BSS_CHANGED_HE_OBSS_PD) 710 633 mt7996_mcu_add_obss_spr(phy, vif, &info->he_obss_pd); 711 634 712 - if (changed & BSS_CHANGED_HE_BSS_COLOR) 713 - mt7996_update_bss_color(hw, vif, &info->he_bss_color); 635 + if (changed & BSS_CHANGED_HE_BSS_COLOR) { 636 + if ((vif->type == NL80211_IFTYPE_AP && 637 + mvif->omac_idx <= HW_BSSID_MAX) || 638 + vif->type == NL80211_IFTYPE_STATION) 639 + mt7996_mcu_update_bss_color(dev, mvif, 640 + &info->he_bss_color); 641 + } 714 642 715 643 if (changed & (BSS_CHANGED_BEACON | 716 644 BSS_CHANGED_BEACON_ENABLED)) { 717 645 mvif->beacon_rates_idx = 718 - mt7996_get_rates_table(hw, vif, true, false); 646 + mt7996_get_rates_table(phy, info, true, false); 719 647 720 - mt7996_mcu_add_beacon(hw, vif, info->enable_beacon); 648 + mt7996_mcu_add_beacon(hw, vif, info); 721 649 } 722 650 723 651 if (changed & (BSS_CHANGED_UNSOL_BCAST_PROBE_RESP | ··· 732 650 if (changed & BSS_CHANGED_MU_GROUPS) 733 651 mt7996_update_mu_group(hw, vif, info); 734 652 653 + if (changed & BSS_CHANGED_TXPOWER && 654 + info->txpower != phy->txpower) { 655 + phy->txpower = info->txpower; 656 + mt7996_mcu_set_txpower_sku(phy); 657 + } 658 + 659 + out: 735 660 mutex_unlock(&dev->mt76.mutex); 736 661 } 737 662 ··· 750 661 struct mt7996_dev *dev = mt7996_hw_dev(hw); 751 662 752 663 mutex_lock(&dev->mt76.mutex); 753 - mt7996_mcu_add_beacon(hw, vif, true); 664 + mt7996_mcu_add_beacon(hw, vif, &vif->bss_conf); 754 665 mutex_unlock(&dev->mt76.mutex); 755 666 } 756 667 ··· 760 671 struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76); 761 672 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; 762 673 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 763 - u8 band_idx = mvif->phy->mt76->band_idx; 764 - int ret, idx; 674 + struct mt7996_vif_link *link = &mvif->deflink; 675 + u8 band_idx = link->phy->mt76->band_idx; 676 + int idx; 765 677 766 678 idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7996_WTBL_STA); 767 679 if (idx < 0) ··· 774 684 msta->wcid.sta = 1; 775 685 msta->wcid.idx = idx; 776 686 msta->wcid.phy_idx = band_idx; 777 - msta->wcid.tx_info |= MT_WCID_TX_INFO_SET; 778 687 779 688 ewma_avg_signal_init(&msta->avg_ack_signal); 780 689 781 690 mt7996_mac_wtbl_update(dev, idx, 782 691 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); 692 + mt7996_mcu_add_sta(dev, vif, &link->mt76, sta, CONN_STATE_DISCONNECT, 693 + true); 783 694 784 - ret = mt7996_mcu_add_sta(dev, vif, sta, true, true); 785 - if (ret) 786 - return ret; 695 + return 0; 696 + } 787 697 788 - return mt7996_mcu_add_rate_ctrl(dev, vif, sta, false); 698 + int mt7996_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif, 699 + struct ieee80211_sta *sta, enum mt76_sta_event ev) 700 + { 701 + struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76); 702 + struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; 703 + struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 704 + struct mt7996_vif_link *link = &mvif->deflink; 705 + int i, ret; 706 + 707 + switch (ev) { 708 + case MT76_STA_EVENT_ASSOC: 709 + ret = mt7996_mcu_add_sta(dev, vif, &link->mt76, sta, 710 + CONN_STATE_CONNECT, true); 711 + if (ret) 712 + return ret; 713 + 714 + ret = mt7996_mcu_add_rate_ctrl(dev, vif, sta, false); 715 + if (ret) 716 + return ret; 717 + 718 + msta->wcid.tx_info |= MT_WCID_TX_INFO_SET; 719 + msta->wcid.sta = 1; 720 + 721 + return 0; 722 + 723 + case MT76_STA_EVENT_AUTHORIZE: 724 + return mt7996_mcu_add_sta(dev, vif, &link->mt76, sta, 725 + CONN_STATE_PORT_SECURE, false); 726 + 727 + case MT76_STA_EVENT_DISASSOC: 728 + for (i = 0; i < ARRAY_SIZE(msta->twt.flow); i++) 729 + mt7996_mac_twt_teardown_flow(dev, msta, i); 730 + 731 + mt7996_mcu_add_sta(dev, vif, &link->mt76, sta, 732 + CONN_STATE_DISCONNECT, false); 733 + msta->wcid.sta_disabled = 1; 734 + msta->wcid.sta = 0; 735 + 736 + return 0; 737 + } 738 + 739 + return 0; 789 740 } 790 741 791 742 void mt7996_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, ··· 834 703 { 835 704 struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76); 836 705 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; 837 - int i; 838 - 839 - mt7996_mcu_add_sta(dev, vif, sta, false, false); 840 706 841 707 mt7996_mac_wtbl_update(dev, msta->wcid.idx, 842 708 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); 843 - 844 - for (i = 0; i < ARRAY_SIZE(msta->twt.flow); i++) 845 - mt7996_mac_twt_teardown_flow(dev, msta, i); 846 709 847 710 spin_lock_bh(&mdev->sta_poll_lock); 848 711 if (!list_empty(&msta->wcid.poll_list)) ··· 856 731 struct ieee80211_vif *vif = info->control.vif; 857 732 struct mt76_wcid *wcid = &dev->mt76.global_wcid; 858 733 734 + if (vif) { 735 + struct mt7996_vif *mvif; 736 + 737 + mvif = (struct mt7996_vif *)vif->drv_priv; 738 + wcid = &mvif->deflink.sta.wcid; 739 + 740 + if (mvif->mt76.roc_phy && 741 + (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN)) { 742 + mphy = mvif->mt76.roc_phy; 743 + if (mphy->roc_link) 744 + wcid = mphy->roc_link->wcid; 745 + } else { 746 + mphy = mt76_vif_link_phy(&mvif->deflink.mt76); 747 + } 748 + } 749 + 859 750 if (control->sta) { 860 751 struct mt7996_sta *sta; 861 752 ··· 879 738 wcid = &sta->wcid; 880 739 } 881 740 882 - if (vif && !control->sta) { 883 - struct mt7996_vif *mvif; 884 - 885 - mvif = (struct mt7996_vif *)vif->drv_priv; 886 - wcid = &mvif->sta.wcid; 741 + if (!mphy) { 742 + ieee80211_free_txskb(hw, skb); 743 + return; 887 744 } 888 745 889 746 mt76_tx(mphy, control->sta, wcid, skb); ··· 889 750 890 751 static int mt7996_set_rts_threshold(struct ieee80211_hw *hw, u32 val) 891 752 { 892 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 893 - int ret; 753 + struct mt7996_dev *dev = mt7996_hw_dev(hw); 754 + int i, ret; 894 755 895 - mutex_lock(&phy->dev->mt76.mutex); 896 - ret = mt7996_mcu_set_rts_thresh(phy, val); 897 - mutex_unlock(&phy->dev->mt76.mutex); 756 + mutex_lock(&dev->mt76.mutex); 757 + 758 + for (i = 0; i < hw->wiphy->n_radio; i++) { 759 + struct mt7996_phy *phy = dev->radio_phy[i]; 760 + 761 + ret = mt7996_mcu_set_rts_thresh(phy, val); 762 + if (ret) 763 + break; 764 + } 765 + 766 + mutex_unlock(&dev->mt76.mutex); 898 767 899 768 return ret; 900 769 } ··· 965 818 } 966 819 967 820 static int 968 - mt7996_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 969 - struct ieee80211_sta *sta) 970 - { 971 - return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NOTEXIST, 972 - IEEE80211_STA_NONE); 973 - } 974 - 975 - static int 976 - mt7996_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 977 - struct ieee80211_sta *sta) 978 - { 979 - return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NONE, 980 - IEEE80211_STA_NOTEXIST); 981 - } 982 - 983 - static int 984 821 mt7996_get_stats(struct ieee80211_hw *hw, 985 822 struct ieee80211_low_level_stats *stats) 986 823 { 987 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 988 824 struct mt7996_dev *dev = mt7996_hw_dev(hw); 989 - struct mt76_mib_stats *mib = &phy->mib; 825 + int i; 990 826 991 827 mutex_lock(&dev->mt76.mutex); 992 828 993 - stats->dot11RTSSuccessCount = mib->rts_cnt; 994 - stats->dot11RTSFailureCount = mib->rts_retries_cnt; 995 - stats->dot11FCSErrorCount = mib->fcs_err_cnt; 996 - stats->dot11ACKFailureCount = mib->ack_fail_cnt; 829 + memset(stats, 0, sizeof(*stats)); 830 + for (i = 0; i < hw->wiphy->n_radio; i++) { 831 + struct mt7996_phy *phy = dev->radio_phy[i]; 832 + struct mt76_mib_stats *mib = &phy->mib; 833 + 834 + stats->dot11RTSSuccessCount += mib->rts_cnt; 835 + stats->dot11RTSFailureCount += mib->rts_retries_cnt; 836 + stats->dot11FCSErrorCount += mib->fcs_err_cnt; 837 + stats->dot11ACKFailureCount += mib->ack_fail_cnt; 838 + } 997 839 998 840 mutex_unlock(&dev->mt76.mutex); 999 841 ··· 992 856 u64 __mt7996_get_tsf(struct ieee80211_hw *hw, struct mt7996_vif *mvif) 993 857 { 994 858 struct mt7996_dev *dev = mt7996_hw_dev(hw); 995 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 859 + struct mt7996_phy *phy = mt7996_vif_link_phy(&mvif->deflink); 996 860 union { 997 861 u64 t64; 998 862 u32 t32[2]; 999 863 } tsf; 1000 864 u16 n; 1001 865 866 + if (!phy) 867 + return 0; 868 + 1002 869 lockdep_assert_held(&dev->mt76.mutex); 1003 870 1004 - n = mvif->mt76.omac_idx > HW_BSSID_MAX ? HW_BSSID_0 1005 - : mvif->mt76.omac_idx; 871 + n = mvif->deflink.mt76.omac_idx > HW_BSSID_MAX ? HW_BSSID_0 872 + : mvif->deflink.mt76.omac_idx; 1006 873 /* TSF software read */ 1007 874 mt76_rmw(dev, MT_LPON_TCR(phy->mt76->band_idx, n), MT_LPON_TCR_SW_MODE, 1008 875 MT_LPON_TCR_SW_READ); ··· 1035 896 { 1036 897 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 1037 898 struct mt7996_dev *dev = mt7996_hw_dev(hw); 1038 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 899 + struct mt7996_phy *phy = mt7996_vif_link_phy(&mvif->deflink); 1039 900 union { 1040 901 u64 t64; 1041 902 u32 t32[2]; 1042 903 } tsf = { .t64 = timestamp, }; 1043 904 u16 n; 1044 905 906 + if (!phy) 907 + return; 908 + 1045 909 mutex_lock(&dev->mt76.mutex); 1046 910 1047 - n = mvif->mt76.omac_idx > HW_BSSID_MAX ? HW_BSSID_0 1048 - : mvif->mt76.omac_idx; 911 + n = mvif->deflink.mt76.omac_idx > HW_BSSID_MAX ? HW_BSSID_0 912 + : mvif->deflink.mt76.omac_idx; 1049 913 mt76_wr(dev, MT_LPON_UTTR0(phy->mt76->band_idx), tsf.t32[0]); 1050 914 mt76_wr(dev, MT_LPON_UTTR1(phy->mt76->band_idx), tsf.t32[1]); 1051 915 /* TSF software overwrite */ ··· 1064 922 { 1065 923 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 1066 924 struct mt7996_dev *dev = mt7996_hw_dev(hw); 1067 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 925 + struct mt7996_phy *phy = mt7996_vif_link_phy(&mvif->deflink); 1068 926 union { 1069 927 u64 t64; 1070 928 u32 t32[2]; 1071 929 } tsf = { .t64 = timestamp, }; 1072 930 u16 n; 1073 931 932 + if (!phy) 933 + return; 934 + 1074 935 mutex_lock(&dev->mt76.mutex); 1075 936 1076 - n = mvif->mt76.omac_idx > HW_BSSID_MAX ? HW_BSSID_0 1077 - : mvif->mt76.omac_idx; 937 + n = mvif->deflink.mt76.omac_idx > HW_BSSID_MAX ? HW_BSSID_0 938 + : mvif->deflink.mt76.omac_idx; 1078 939 mt76_wr(dev, MT_LPON_UTTR0(phy->mt76->band_idx), tsf.t32[0]); 1079 940 mt76_wr(dev, MT_LPON_UTTR1(phy->mt76->band_idx), tsf.t32[1]); 1080 941 /* TSF software adjust*/ ··· 1090 945 static void 1091 946 mt7996_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class) 1092 947 { 1093 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 1094 - struct mt7996_dev *dev = phy->dev; 948 + struct mt7996_dev *dev = mt7996_hw_dev(hw); 949 + struct mt7996_phy *phy; 1095 950 1096 951 mutex_lock(&dev->mt76.mutex); 1097 - phy->coverage_class = max_t(s16, coverage_class, 0); 1098 - mt7996_mac_set_coverage_class(phy); 952 + mt7996_for_each_phy(dev, phy) { 953 + phy->coverage_class = max_t(s16, coverage_class, 0); 954 + mt7996_mac_set_coverage_class(phy); 955 + } 1099 956 mutex_unlock(&dev->mt76.mutex); 1100 957 } 1101 958 ··· 1105 958 mt7996_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) 1106 959 { 1107 960 struct mt7996_dev *dev = mt7996_hw_dev(hw); 1108 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 1109 - int max_nss = hweight8(hw->wiphy->available_antennas_tx); 1110 - u8 band_idx = phy->mt76->band_idx, shift = dev->chainshift[band_idx]; 961 + int i; 1111 962 1112 - if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss) 963 + if (tx_ant != rx_ant) 1113 964 return -EINVAL; 1114 965 1115 - if ((BIT(hweight8(tx_ant)) - 1) != tx_ant) 1116 - tx_ant = BIT(ffs(tx_ant) - 1) - 1; 966 + for (i = 0; i < hw->wiphy->n_radio; i++) { 967 + struct mt7996_phy *phy = dev->radio_phy[i]; 968 + 969 + if (!(tx_ant & phy->orig_chainmask)) 970 + return -EINVAL; 971 + } 1117 972 1118 973 mutex_lock(&dev->mt76.mutex); 1119 974 1120 - phy->mt76->antenna_mask = tx_ant; 975 + for (i = 0; i < hw->wiphy->n_radio; i++) { 976 + struct mt7996_phy *phy = dev->radio_phy[i]; 977 + u8 band_idx = phy->mt76->band_idx; 978 + u8 shift = dev->chainshift[band_idx]; 1121 979 1122 - /* restore to the origin chainmask which might have auxiliary path */ 1123 - if (hweight8(tx_ant) == max_nss && band_idx < MT_BAND2) 1124 - phy->mt76->chainmask = ((dev->chainmask >> shift) & 1125 - (BIT(dev->chainshift[band_idx + 1] - shift) - 1)) << shift; 1126 - else if (hweight8(tx_ant) == max_nss) 1127 - phy->mt76->chainmask = (dev->chainmask >> shift) << shift; 1128 - else 1129 - phy->mt76->chainmask = tx_ant << shift; 980 + phy->mt76->chainmask = tx_ant & phy->orig_chainmask; 981 + phy->mt76->antenna_mask = phy->mt76->chainmask >> shift; 1130 982 1131 - mt76_set_stream_caps(phy->mt76, true); 1132 - mt7996_set_stream_vht_txbf_caps(phy); 1133 - mt7996_set_stream_he_eht_caps(phy); 1134 - mt7996_mcu_set_txpower_sku(phy); 983 + mt76_set_stream_caps(phy->mt76, true); 984 + mt7996_set_stream_vht_txbf_caps(phy); 985 + mt7996_set_stream_he_eht_caps(phy); 986 + mt7996_mcu_set_txpower_sku(phy); 987 + } 1135 988 1136 989 mutex_unlock(&dev->mt76.mutex); 1137 990 ··· 1143 996 struct ieee80211_sta *sta, 1144 997 struct station_info *sinfo) 1145 998 { 1146 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 999 + struct mt7996_dev *dev = mt7996_hw_dev(hw); 1147 1000 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; 1148 1001 struct rate_info *txrate = &msta->wcid.rate; 1149 1002 ··· 1177 1030 sinfo->avg_ack_signal = -(s8)ewma_avg_signal_read(&msta->avg_ack_signal); 1178 1031 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG); 1179 1032 1180 - if (mtk_wed_device_active(&phy->dev->mt76.mmio.wed)) { 1033 + if (mtk_wed_device_active(&dev->mt76.mmio.wed)) { 1181 1034 sinfo->tx_bytes = msta->wcid.stats.tx_bytes; 1182 1035 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64); 1183 1036 ··· 1195 1048 static void mt7996_sta_rc_work(void *data, struct ieee80211_sta *sta) 1196 1049 { 1197 1050 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; 1198 - struct mt7996_dev *dev = msta->vif->phy->dev; 1051 + struct mt7996_dev *dev = msta->vif->deflink.phy->dev; 1199 1052 u32 *changed = data; 1200 1053 1201 1054 spin_lock_bh(&dev->mt76.sta_poll_lock); ··· 1210 1063 struct ieee80211_link_sta *link_sta, 1211 1064 u32 changed) 1212 1065 { 1066 + struct mt7996_dev *dev = mt7996_hw_dev(hw); 1213 1067 struct ieee80211_sta *sta = link_sta->sta; 1214 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 1215 - struct mt7996_dev *dev = phy->dev; 1216 1068 1217 1069 mt7996_sta_rc_work(&changed, sta); 1218 1070 ieee80211_queue_work(hw, &dev->rc_work); ··· 1221 1075 mt7996_set_bitrate_mask(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1222 1076 const struct cfg80211_bitrate_mask *mask) 1223 1077 { 1078 + struct mt7996_dev *dev = mt7996_hw_dev(hw); 1224 1079 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 1225 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 1226 - struct mt7996_dev *dev = phy->dev; 1227 1080 u32 changed = IEEE80211_RC_SUPP_RATES_CHANGED; 1228 1081 1229 - mvif->bitrate_mask = *mask; 1082 + mvif->deflink.bitrate_mask = *mask; 1230 1083 1231 1084 /* if multiple rates across different preambles are given we can 1232 1085 * reconfigure this info with all peers using sta_rec command with ··· 1254 1109 else 1255 1110 clear_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags); 1256 1111 1112 + if (!msta->wcid.sta) 1113 + return; 1114 + 1257 1115 mt7996_mcu_wtbl_update_hdr_trans(dev, vif, sta); 1258 1116 } 1259 1117 ··· 1272 1124 set_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags); 1273 1125 else 1274 1126 clear_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags); 1127 + 1128 + if (!msta->wcid.sta) 1129 + return; 1275 1130 1276 1131 mt7996_mcu_wtbl_update_hdr_trans(dev, vif, sta); 1277 1132 } ··· 1409 1258 struct mt76_ethtool_worker_info *wi = wi_data; 1410 1259 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; 1411 1260 1412 - if (msta->vif->mt76.idx != wi->idx) 1261 + if (msta->vif->deflink.mt76.idx != wi->idx) 1413 1262 return; 1414 1263 1415 1264 mt76_ethtool_worker(wi, &msta->wcid.stats, true); ··· 1421 1270 struct ethtool_stats *stats, u64 *data) 1422 1271 { 1423 1272 struct mt7996_dev *dev = mt7996_hw_dev(hw); 1424 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 1425 1273 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 1274 + struct mt7996_phy *phy = mt7996_vif_link_phy(&mvif->deflink); 1426 1275 struct mt76_mib_stats *mib = &phy->mib; 1427 1276 struct mt76_ethtool_worker_info wi = { 1428 1277 .data = data, 1429 - .idx = mvif->mt76.idx, 1278 + .idx = mvif->deflink.mt76.idx, 1430 1279 }; 1431 1280 /* See mt7996_ampdu_stat_read_phy, etc */ 1432 1281 int i, ei = 0; 1282 + 1283 + if (!phy) 1284 + return; 1433 1285 1434 1286 mutex_lock(&dev->mt76.mutex); 1435 1287 ··· 1527 1373 mt7996_set_radar_background(struct ieee80211_hw *hw, 1528 1374 struct cfg80211_chan_def *chandef) 1529 1375 { 1530 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 1531 - struct mt7996_dev *dev = phy->dev; 1376 + struct mt7996_dev *dev = mt7996_hw_dev(hw); 1377 + struct mt7996_phy *phy; 1532 1378 int ret = -EINVAL; 1533 1379 bool running; 1380 + 1381 + if (chandef) 1382 + phy = mt7996_band_phy(dev, chandef->chan->band); 1383 + else 1384 + phy = dev->rdd2_phy; 1385 + if (!phy) 1386 + return -EINVAL; 1534 1387 1535 1388 mutex_lock(&dev->mt76.mutex); 1536 1389 ··· 1589 1428 { 1590 1429 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 1591 1430 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; 1431 + struct mt7996_vif_link *mlink = &mvif->deflink; 1592 1432 struct mt7996_dev *dev = mt7996_hw_dev(hw); 1593 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 1594 1433 struct mtk_wed_device *wed = &dev->mt76.mmio.wed; 1434 + struct mt7996_phy *phy; 1435 + 1436 + phy = mt7996_vif_link_phy(mlink); 1437 + if (!phy) 1438 + return -ENODEV; 1595 1439 1596 1440 if (phy != &dev->phy && phy->mt76->band_idx == MT_BAND2) 1597 1441 wed = &dev->mt76.mmio.wed_hif2; ··· 1604 1438 if (!mtk_wed_device_active(wed)) 1605 1439 return -ENODEV; 1606 1440 1607 - if (msta->wcid.idx > MT7996_WTBL_STA) 1441 + if (!msta->wcid.sta || msta->wcid.idx > MT7996_WTBL_STA) 1608 1442 return -EIO; 1609 1443 1610 1444 path->type = DEV_PATH_MTK_WDMA; 1611 1445 path->dev = ctx->dev; 1612 1446 path->mtk_wdma.wdma_idx = wed->wdma_idx; 1613 - path->mtk_wdma.bss = mvif->mt76.idx; 1447 + path->mtk_wdma.bss = mvif->deflink.mt76.idx; 1614 1448 path->mtk_wdma.queue = 0; 1615 1449 path->mtk_wdma.wcid = msta->wcid.idx; 1616 1450 ··· 1623 1457 #endif 1624 1458 1625 1459 const struct ieee80211_ops mt7996_ops = { 1626 - .add_chanctx = ieee80211_emulate_add_chanctx, 1627 - .remove_chanctx = ieee80211_emulate_remove_chanctx, 1628 - .change_chanctx = ieee80211_emulate_change_chanctx, 1629 - .switch_vif_chanctx = ieee80211_emulate_switch_vif_chanctx, 1460 + .add_chanctx = mt76_add_chanctx, 1461 + .remove_chanctx = mt76_remove_chanctx, 1462 + .change_chanctx = mt76_change_chanctx, 1463 + .assign_vif_chanctx = mt76_assign_vif_chanctx, 1464 + .unassign_vif_chanctx = mt76_unassign_vif_chanctx, 1465 + .switch_vif_chanctx = mt76_switch_vif_chanctx, 1630 1466 .tx = mt7996_tx, 1631 1467 .start = mt7996_start, 1632 1468 .stop = mt7996_stop, ··· 1638 1470 .conf_tx = mt7996_conf_tx, 1639 1471 .configure_filter = mt7996_configure_filter, 1640 1472 .bss_info_changed = mt7996_bss_info_changed, 1641 - .sta_add = mt7996_sta_add, 1642 - .sta_remove = mt7996_sta_remove, 1473 + .sta_state = mt76_sta_state, 1643 1474 .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove, 1644 1475 .link_sta_rc_update = mt7996_sta_rc_update, 1645 1476 .set_key = mt7996_set_key, 1646 1477 .ampdu_action = mt7996_ampdu_action, 1647 1478 .set_rts_threshold = mt7996_set_rts_threshold, 1648 1479 .wake_tx_queue = mt76_wake_tx_queue, 1649 - .sw_scan_start = mt76_sw_scan, 1650 - .sw_scan_complete = mt76_sw_scan_complete, 1480 + .hw_scan = mt76_hw_scan, 1481 + .cancel_hw_scan = mt76_cancel_hw_scan, 1482 + .remain_on_channel = mt76_remain_on_channel, 1483 + .cancel_remain_on_channel = mt76_cancel_remain_on_channel, 1651 1484 .release_buffered_frames = mt76_release_buffered_frames, 1652 1485 .get_txpower = mt76_get_txpower, 1653 1486 .channel_switch_beacon = mt7996_channel_switch_beacon,
+287 -217
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
··· 14 14 char *_fw; \ 15 15 switch (mt76_chip(&(_dev)->mt76)) { \ 16 16 case 0x7992: \ 17 - _fw = MT7992_##name; \ 17 + switch ((_dev)->var.type) { \ 18 + case MT7992_VAR_TYPE_23: \ 19 + _fw = MT7992_##name##_23; \ 20 + break; \ 21 + default: \ 22 + _fw = MT7992_##name; \ 23 + } \ 18 24 break; \ 19 25 case 0x7990: \ 20 26 default: \ 21 - _fw = MT7996_##name; \ 27 + switch ((_dev)->var.type) { \ 28 + case MT7996_VAR_TYPE_233: \ 29 + _fw = MT7996_##name##_233; \ 30 + break; \ 31 + default: \ 32 + _fw = MT7996_##name; \ 33 + } \ 22 34 break; \ 23 35 } \ 24 36 _fw; \ ··· 122 110 u16 mcs_map) 123 111 { 124 112 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; 125 - enum nl80211_band band = msta->vif->phy->mt76->chandef.chan->band; 126 - const u16 *mask = msta->vif->bitrate_mask.control[band].he_mcs; 113 + enum nl80211_band band = msta->vif->deflink.phy->mt76->chandef.chan->band; 114 + const u16 *mask = msta->vif->deflink.bitrate_mask.control[band].he_mcs; 127 115 int nss, max_nss = sta->deflink.rx_nss > 3 ? 4 : sta->deflink.rx_nss; 128 116 129 117 for (nss = 0; nss < max_nss; nss++) { ··· 756 744 } 757 745 758 746 static void 759 - mt7996_mcu_bss_rfch_tlv(struct sk_buff *skb, struct ieee80211_vif *vif, 760 - struct mt7996_phy *phy) 747 + mt7996_mcu_bss_rfch_tlv(struct sk_buff *skb, struct mt7996_phy *phy) 761 748 { 762 749 static const u8 rlm_ch_band[] = { 763 750 [NL80211_BAND_2GHZ] = 1, ··· 786 775 } 787 776 788 777 static void 789 - mt7996_mcu_bss_ra_tlv(struct sk_buff *skb, struct ieee80211_vif *vif, 790 - struct mt7996_phy *phy) 778 + mt7996_mcu_bss_ra_tlv(struct sk_buff *skb, struct mt7996_phy *phy) 791 779 { 792 780 struct bss_ra_tlv *ra; 793 781 struct tlv *tlv; ··· 799 789 800 790 static void 801 791 mt7996_mcu_bss_he_tlv(struct sk_buff *skb, struct ieee80211_vif *vif, 792 + struct ieee80211_bss_conf *link_conf, 802 793 struct mt7996_phy *phy) 803 794 { 804 795 #define DEFAULT_HE_PE_DURATION 4 ··· 813 802 tlv = mt7996_mcu_add_uni_tlv(skb, UNI_BSS_INFO_HE_BASIC, sizeof(*he)); 814 803 815 804 he = (struct bss_info_uni_he *)tlv; 816 - he->he_pe_duration = vif->bss_conf.htc_trig_based_pkt_ext; 805 + he->he_pe_duration = link_conf->htc_trig_based_pkt_ext; 817 806 if (!he->he_pe_duration) 818 807 he->he_pe_duration = DEFAULT_HE_PE_DURATION; 819 808 820 - he->he_rts_thres = cpu_to_le16(vif->bss_conf.frame_time_rts_th); 809 + he->he_rts_thres = cpu_to_le16(link_conf->frame_time_rts_th); 821 810 if (!he->he_rts_thres) 822 811 he->he_rts_thres = cpu_to_le16(DEFAULT_HE_DURATION_RTS_THRES); 823 812 ··· 827 816 } 828 817 829 818 static void 830 - mt7996_mcu_bss_mbssid_tlv(struct sk_buff *skb, struct ieee80211_vif *vif, 831 - struct mt7996_phy *phy, int enable) 819 + mt7996_mcu_bss_mbssid_tlv(struct sk_buff *skb, struct ieee80211_bss_conf *link_conf, 820 + bool enable) 832 821 { 833 822 struct bss_info_uni_mbssid *mbssid; 834 823 struct tlv *tlv; 835 824 836 - if (!vif->bss_conf.bssid_indicator && enable) 825 + if (!link_conf->bssid_indicator && enable) 837 826 return; 838 827 839 828 tlv = mt7996_mcu_add_uni_tlv(skb, UNI_BSS_INFO_11V_MBSSID, sizeof(*mbssid)); ··· 841 830 mbssid = (struct bss_info_uni_mbssid *)tlv; 842 831 843 832 if (enable) { 844 - mbssid->max_indicator = vif->bss_conf.bssid_indicator; 845 - mbssid->mbss_idx = vif->bss_conf.bssid_index; 833 + mbssid->max_indicator = link_conf->bssid_indicator; 834 + mbssid->mbss_idx = link_conf->bssid_index; 846 835 mbssid->tx_bss_omac_idx = 0; 847 836 } 848 837 } 849 838 850 839 static void 851 - mt7996_mcu_bss_bmc_tlv(struct sk_buff *skb, struct ieee80211_vif *vif, 840 + mt7996_mcu_bss_bmc_tlv(struct sk_buff *skb, struct mt76_vif_link *mlink, 852 841 struct mt7996_phy *phy) 853 842 { 854 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 855 843 struct bss_rate_tlv *bmc; 856 844 struct cfg80211_chan_def *chandef = &phy->mt76->chandef; 857 845 enum nl80211_band band = chandef->chan->band; 858 846 struct tlv *tlv; 859 - u8 idx = mvif->mcast_rates_idx ? 860 - mvif->mcast_rates_idx : mvif->basic_rates_idx; 847 + u8 idx = mlink->mcast_rates_idx ? 848 + mlink->mcast_rates_idx : mlink->basic_rates_idx; 861 849 862 850 tlv = mt7996_mcu_add_uni_tlv(skb, UNI_BSS_INFO_RATE, sizeof(*bmc)); 863 851 ··· 880 870 } 881 871 882 872 static void 883 - mt7996_mcu_bss_mld_tlv(struct sk_buff *skb, struct ieee80211_vif *vif) 873 + mt7996_mcu_bss_mld_tlv(struct sk_buff *skb, struct mt76_vif_link *mlink) 884 874 { 885 - struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 886 875 struct bss_mld_tlv *mld; 887 876 struct tlv *tlv; 888 877 ··· 889 880 890 881 mld = (struct bss_mld_tlv *)tlv; 891 882 mld->group_mld_id = 0xff; 892 - mld->own_mld_id = mvif->mt76.idx; 883 + mld->own_mld_id = mlink->idx; 893 884 mld->remap_idx = 0xff; 894 885 } 895 886 896 887 static void 897 - mt7996_mcu_bss_sec_tlv(struct sk_buff *skb, struct ieee80211_vif *vif) 888 + mt7996_mcu_bss_sec_tlv(struct sk_buff *skb, struct mt76_vif_link *mlink) 898 889 { 899 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 900 890 struct bss_sec_tlv *sec; 901 891 struct tlv *tlv; 902 892 903 893 tlv = mt7996_mcu_add_uni_tlv(skb, UNI_BSS_INFO_SEC, sizeof(*sec)); 904 894 905 895 sec = (struct bss_sec_tlv *)tlv; 906 - sec->cipher = mvif->cipher; 896 + sec->cipher = mlink->cipher; 907 897 } 908 898 909 899 static int 910 - mt7996_mcu_muar_config(struct mt7996_phy *phy, struct ieee80211_vif *vif, 911 - bool bssid, bool enable) 900 + mt7996_mcu_muar_config(struct mt7996_dev *dev, struct mt76_vif_link *mlink, 901 + const u8 *addr, bool bssid, bool enable) 912 902 { 913 903 #define UNI_MUAR_ENTRY 2 914 - struct mt7996_dev *dev = phy->dev; 915 - struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 916 - u32 idx = mvif->mt76.omac_idx - REPEATER_BSSID_START; 917 - const u8 *addr = vif->addr; 918 - 904 + u32 idx = mlink->omac_idx - REPEATER_BSSID_START; 919 905 struct { 920 906 struct { 921 907 u8 band; ··· 927 923 u8 addr[ETH_ALEN]; 928 924 u8 __rsv[2]; 929 925 } __packed req = { 930 - .hdr.band = phy->mt76->band_idx, 926 + .hdr.band = mlink->band_idx, 931 927 .tag = cpu_to_le16(UNI_MUAR_ENTRY), 932 928 .len = cpu_to_le16(sizeof(req) - sizeof(req.hdr)), 933 929 .smesh = false, 934 930 .index = idx * 2 + bssid, 935 931 .entry_add = true, 936 932 }; 937 - 938 - if (bssid) 939 - addr = vif->bss_conf.bssid; 940 933 941 934 if (enable) 942 935 memcpy(req.addr, addr, ETH_ALEN); ··· 943 942 } 944 943 945 944 static void 946 - mt7996_mcu_bss_ifs_timing_tlv(struct sk_buff *skb, struct ieee80211_vif *vif) 945 + mt7996_mcu_bss_ifs_timing_tlv(struct sk_buff *skb, struct mt7996_phy *phy) 947 946 { 948 - struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 949 - struct mt7996_phy *phy = mvif->phy; 950 947 struct bss_ifs_time_tlv *ifs_time; 951 948 struct tlv *tlv; 952 949 bool is_2ghz = phy->mt76->chandef.chan->band == NL80211_BAND_2GHZ; ··· 971 972 static int 972 973 mt7996_mcu_bss_basic_tlv(struct sk_buff *skb, 973 974 struct ieee80211_vif *vif, 974 - struct ieee80211_sta *sta, 975 + struct ieee80211_bss_conf *link_conf, 976 + struct mt76_vif_link *mvif, 975 977 struct mt76_phy *phy, u16 wlan_idx, 976 978 bool enable) 977 979 { 978 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 979 980 struct cfg80211_chan_def *chandef = &phy->chandef; 980 981 struct mt76_connac_bss_basic_tlv *bss; 981 982 u32 type = CONNECTION_INFRA_AP; 982 983 u16 sta_wlan_idx = wlan_idx; 984 + struct ieee80211_sta *sta; 983 985 struct tlv *tlv; 984 986 int idx; 985 987 ··· 992 992 case NL80211_IFTYPE_STATION: 993 993 if (enable) { 994 994 rcu_read_lock(); 995 - if (!sta) 996 - sta = ieee80211_find_sta(vif, 997 - vif->bss_conf.bssid); 995 + sta = ieee80211_find_sta(vif, vif->bss_conf.bssid); 998 996 /* TODO: enable BSS_INFO_UAPSD & BSS_INFO_PM */ 999 997 if (sta) { 1000 998 struct mt76_wcid *wcid; ··· 1015 1017 tlv = mt7996_mcu_add_uni_tlv(skb, UNI_BSS_INFO_BASIC, sizeof(*bss)); 1016 1018 1017 1019 bss = (struct mt76_connac_bss_basic_tlv *)tlv; 1018 - bss->bcn_interval = cpu_to_le16(vif->bss_conf.beacon_int); 1019 - bss->dtim_period = vif->bss_conf.dtim_period; 1020 + bss->bcn_interval = cpu_to_le16(link_conf->beacon_int); 1021 + bss->dtim_period = link_conf->dtim_period; 1020 1022 bss->bmc_tx_wlan_idx = cpu_to_le16(wlan_idx); 1021 1023 bss->sta_idx = cpu_to_le16(sta_wlan_idx); 1022 1024 bss->conn_type = cpu_to_le32(type); ··· 1034 1036 return 0; 1035 1037 } 1036 1038 1037 - memcpy(bss->bssid, vif->bss_conf.bssid, ETH_ALEN); 1038 - bss->bcn_interval = cpu_to_le16(vif->bss_conf.beacon_int); 1039 + memcpy(bss->bssid, link_conf->bssid, ETH_ALEN); 1040 + bss->bcn_interval = cpu_to_le16(link_conf->beacon_int); 1039 1041 bss->dtim_period = vif->bss_conf.dtim_period; 1040 1042 bss->phymode = mt76_connac_get_phy_mode(phy, vif, 1041 1043 chandef->chan->band, NULL); 1042 - bss->phymode_ext = mt76_connac_get_phy_mode_ext(phy, vif, 1044 + bss->phymode_ext = mt76_connac_get_phy_mode_ext(phy, &vif->bss_conf, 1043 1045 chandef->chan->band); 1044 1046 1045 1047 return 0; 1046 1048 } 1047 1049 1048 1050 static struct sk_buff * 1049 - __mt7996_mcu_alloc_bss_req(struct mt76_dev *dev, struct mt76_vif *mvif, int len) 1051 + __mt7996_mcu_alloc_bss_req(struct mt76_dev *dev, struct mt76_vif_link *mvif, int len) 1050 1052 { 1051 1053 struct bss_req_hdr hdr = { 1052 1054 .bss_idx = mvif->idx, ··· 1062 1064 return skb; 1063 1065 } 1064 1066 1065 - int mt7996_mcu_add_bss_info(struct mt7996_phy *phy, 1066 - struct ieee80211_vif *vif, int enable) 1067 + int mt7996_mcu_add_bss_info(struct mt7996_phy *phy, struct ieee80211_vif *vif, 1068 + struct ieee80211_bss_conf *link_conf, 1069 + struct mt76_vif_link *mlink, int enable) 1067 1070 { 1068 - struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 1069 1071 struct mt7996_dev *dev = phy->dev; 1070 1072 struct sk_buff *skb; 1071 1073 1072 - if (mvif->mt76.omac_idx >= REPEATER_BSSID_START) { 1073 - mt7996_mcu_muar_config(phy, vif, false, enable); 1074 - mt7996_mcu_muar_config(phy, vif, true, enable); 1074 + if (mlink->omac_idx >= REPEATER_BSSID_START) { 1075 + mt7996_mcu_muar_config(dev, mlink, link_conf->addr, false, enable); 1076 + mt7996_mcu_muar_config(dev, mlink, link_conf->bssid, true, enable); 1075 1077 } 1076 1078 1077 - skb = __mt7996_mcu_alloc_bss_req(&dev->mt76, &mvif->mt76, 1079 + skb = __mt7996_mcu_alloc_bss_req(&dev->mt76, mlink, 1078 1080 MT7996_BSS_UPDATE_MAX_SIZE); 1079 1081 if (IS_ERR(skb)) 1080 1082 return PTR_ERR(skb); 1081 1083 1082 1084 /* bss_basic must be first */ 1083 - mt7996_mcu_bss_basic_tlv(skb, vif, NULL, phy->mt76, 1084 - mvif->sta.wcid.idx, enable); 1085 - mt7996_mcu_bss_sec_tlv(skb, vif); 1085 + mt7996_mcu_bss_basic_tlv(skb, vif, link_conf, mlink, phy->mt76, 1086 + mlink->wcid->idx, enable); 1087 + mt7996_mcu_bss_sec_tlv(skb, mlink); 1086 1088 1087 1089 if (vif->type == NL80211_IFTYPE_MONITOR) 1088 1090 goto out; 1089 1091 1090 1092 if (enable) { 1091 - mt7996_mcu_bss_rfch_tlv(skb, vif, phy); 1092 - mt7996_mcu_bss_bmc_tlv(skb, vif, phy); 1093 - mt7996_mcu_bss_ra_tlv(skb, vif, phy); 1093 + mt7996_mcu_bss_rfch_tlv(skb, phy); 1094 + mt7996_mcu_bss_bmc_tlv(skb, mlink, phy); 1095 + mt7996_mcu_bss_ra_tlv(skb, phy); 1094 1096 mt7996_mcu_bss_txcmd_tlv(skb, true); 1095 - mt7996_mcu_bss_ifs_timing_tlv(skb, vif); 1097 + mt7996_mcu_bss_ifs_timing_tlv(skb, phy); 1096 1098 1097 1099 if (vif->bss_conf.he_support) 1098 - mt7996_mcu_bss_he_tlv(skb, vif, phy); 1100 + mt7996_mcu_bss_he_tlv(skb, vif, link_conf, phy); 1099 1101 1100 1102 /* this tag is necessary no matter if the vif is MLD */ 1101 - mt7996_mcu_bss_mld_tlv(skb, vif); 1103 + mt7996_mcu_bss_mld_tlv(skb, mlink); 1102 1104 } 1103 1105 1104 - mt7996_mcu_bss_mbssid_tlv(skb, vif, phy, enable); 1106 + mt7996_mcu_bss_mbssid_tlv(skb, link_conf, enable); 1105 1107 1106 1108 out: 1107 1109 return mt76_mcu_skb_send_msg(&dev->mt76, skb, 1108 1110 MCU_WMWA_UNI_CMD(BSS_INFO_UPDATE), true); 1109 1111 } 1110 1112 1111 - int mt7996_mcu_set_timing(struct mt7996_phy *phy, struct ieee80211_vif *vif) 1113 + int mt7996_mcu_set_timing(struct mt7996_phy *phy, struct ieee80211_vif *vif, 1114 + struct ieee80211_bss_conf *link_conf) 1112 1115 { 1113 - struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 1114 1116 struct mt7996_dev *dev = phy->dev; 1117 + struct mt76_vif_link *mlink = mt76_vif_conf_link(&dev->mt76, vif, link_conf); 1115 1118 struct sk_buff *skb; 1116 1119 1117 - skb = __mt7996_mcu_alloc_bss_req(&dev->mt76, &mvif->mt76, 1120 + skb = __mt7996_mcu_alloc_bss_req(&dev->mt76, mlink, 1118 1121 MT7996_BSS_UPDATE_MAX_SIZE); 1119 1122 if (IS_ERR(skb)) 1120 1123 return PTR_ERR(skb); 1121 1124 1122 - mt7996_mcu_bss_ifs_timing_tlv(skb, vif); 1125 + mt7996_mcu_bss_ifs_timing_tlv(skb, phy); 1123 1126 1124 1127 return mt76_mcu_skb_send_msg(&dev->mt76, skb, 1125 1128 MCU_WMWA_UNI_CMD(BSS_INFO_UPDATE), true); 1126 1129 } 1127 1130 1128 1131 static int 1129 - mt7996_mcu_sta_ba(struct mt7996_dev *dev, struct mt76_vif *mvif, 1132 + mt7996_mcu_sta_ba(struct mt7996_dev *dev, struct mt76_vif_link *mvif, 1130 1133 struct ieee80211_ampdu_params *params, 1131 1134 bool enable, bool tx) 1132 1135 { ··· 1167 1168 if (enable && !params->amsdu) 1168 1169 msta->wcid.amsdu = false; 1169 1170 1170 - return mt7996_mcu_sta_ba(dev, &mvif->mt76, params, enable, true); 1171 + return mt7996_mcu_sta_ba(dev, &mvif->deflink.mt76, params, enable, true); 1171 1172 } 1172 1173 1173 1174 int mt7996_mcu_add_rx_ba(struct mt7996_dev *dev, ··· 1177 1178 struct mt7996_sta *msta = (struct mt7996_sta *)params->sta->drv_priv; 1178 1179 struct mt7996_vif *mvif = msta->vif; 1179 1180 1180 - return mt7996_mcu_sta_ba(dev, &mvif->mt76, params, enable, false); 1181 + return mt7996_mcu_sta_ba(dev, &mvif->deflink.mt76, params, enable, false); 1181 1182 } 1182 1183 1183 1184 static void ··· 1460 1461 } 1461 1462 1462 1463 static void 1463 - mt7996_mcu_sta_sounding_rate(struct sta_rec_bf *bf) 1464 + mt7996_mcu_sta_sounding_rate(struct sta_rec_bf *bf, struct mt7996_phy *phy) 1464 1465 { 1465 1466 bf->sounding_phy = MT_PHY_TYPE_OFDM; 1466 1467 bf->ndp_rate = 0; /* mcs0 */ 1467 - bf->ndpa_rate = MT7996_CFEND_RATE_DEFAULT; /* ofdm 24m */ 1468 + if (is_mt7996(phy->mt76->dev)) 1469 + bf->ndpa_rate = MT7996_CFEND_RATE_DEFAULT; /* ofdm 24m */ 1470 + else 1471 + bf->ndpa_rate = MT7992_CFEND_RATE_DEFAULT; /* ofdm 6m */ 1472 + 1468 1473 bf->rept_poll_rate = MT7996_CFEND_RATE_DEFAULT; /* ofdm 24m */ 1469 1474 } 1470 1475 1471 1476 static void 1472 1477 mt7996_mcu_sta_bfer_ht(struct ieee80211_sta *sta, struct mt7996_phy *phy, 1473 - struct sta_rec_bf *bf) 1478 + struct sta_rec_bf *bf, bool explicit) 1474 1479 { 1475 1480 struct ieee80211_mcs_info *mcs = &sta->deflink.ht_cap.mcs; 1476 1481 u8 n = 0; ··· 1494 1491 1495 1492 bf->nrow = hweight8(phy->mt76->antenna_mask) - 1; 1496 1493 bf->ncol = min_t(u8, bf->nrow, n); 1497 - bf->ibf_ncol = n; 1494 + bf->ibf_ncol = explicit ? min_t(u8, MT7996_IBF_MAX_NC, bf->ncol) : 1495 + min_t(u8, MT7996_IBF_MAX_NC, n); 1498 1496 } 1499 1497 1500 1498 static void ··· 1513 1509 if (explicit) { 1514 1510 u8 sts, snd_dim; 1515 1511 1516 - mt7996_mcu_sta_sounding_rate(bf); 1512 + mt7996_mcu_sta_sounding_rate(bf, phy); 1517 1513 1518 1514 sts = FIELD_GET(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK, 1519 1515 pc->cap); ··· 1521 1517 vc->cap); 1522 1518 bf->nrow = min_t(u8, min_t(u8, snd_dim, sts), tx_ant); 1523 1519 bf->ncol = min_t(u8, nss_mcs, bf->nrow); 1524 - bf->ibf_ncol = bf->ncol; 1520 + bf->ibf_ncol = min_t(u8, MT7996_IBF_MAX_NC, bf->ncol); 1525 1521 1526 1522 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_160) 1527 1523 bf->nrow = 1; 1528 1524 } else { 1529 1525 bf->nrow = tx_ant; 1530 1526 bf->ncol = min_t(u8, nss_mcs, bf->nrow); 1531 - bf->ibf_ncol = nss_mcs; 1527 + bf->ibf_ncol = min_t(u8, MT7996_IBF_MAX_NC, nss_mcs); 1532 1528 1533 1529 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_160) 1534 1530 bf->ibf_nrow = 1; ··· 1537 1533 1538 1534 static void 1539 1535 mt7996_mcu_sta_bfer_he(struct ieee80211_sta *sta, struct ieee80211_vif *vif, 1540 - struct mt7996_phy *phy, struct sta_rec_bf *bf) 1536 + struct mt7996_phy *phy, struct sta_rec_bf *bf, 1537 + bool explicit) 1541 1538 { 1542 1539 struct ieee80211_sta_he_cap *pc = &sta->deflink.he_cap; 1543 1540 struct ieee80211_he_cap_elem *pe = &pc->he_cap_elem; ··· 1554 1549 1555 1550 bf->tx_mode = MT_PHY_TYPE_HE_SU; 1556 1551 1557 - mt7996_mcu_sta_sounding_rate(bf); 1552 + mt7996_mcu_sta_sounding_rate(bf, phy); 1558 1553 1559 1554 bf->trigger_su = HE_PHY(CAP6_TRIG_SU_BEAMFORMING_FB, 1560 1555 pe->phy_cap_info[6]); ··· 1566 1561 pe->phy_cap_info[4]); 1567 1562 bf->nrow = min_t(u8, snd_dim, sts); 1568 1563 bf->ncol = min_t(u8, nss_mcs, bf->nrow); 1569 - bf->ibf_ncol = bf->ncol; 1564 + bf->ibf_ncol = explicit ? min_t(u8, MT7996_IBF_MAX_NC, bf->ncol) : 1565 + min_t(u8, MT7996_IBF_MAX_NC, nss_mcs); 1570 1566 1571 1567 if (sta->deflink.bandwidth != IEEE80211_STA_RX_BW_160) 1572 1568 return; ··· 1602 1596 1603 1597 static void 1604 1598 mt7996_mcu_sta_bfer_eht(struct ieee80211_sta *sta, struct ieee80211_vif *vif, 1605 - struct mt7996_phy *phy, struct sta_rec_bf *bf) 1599 + struct mt7996_phy *phy, struct sta_rec_bf *bf, 1600 + bool explicit) 1606 1601 { 1607 1602 struct ieee80211_sta_eht_cap *pc = &sta->deflink.eht_cap; 1608 1603 struct ieee80211_eht_cap_elem_fixed *pe = &pc->eht_cap_elem; ··· 1617 1610 1618 1611 bf->tx_mode = MT_PHY_TYPE_EHT_MU; 1619 1612 1620 - mt7996_mcu_sta_sounding_rate(bf); 1613 + mt7996_mcu_sta_sounding_rate(bf, phy); 1621 1614 1622 1615 bf->trigger_su = EHT_PHY(CAP3_TRIG_SU_BF_FDBK, pe->phy_cap_info[3]); 1623 1616 bf->trigger_mu = EHT_PHY(CAP3_TRIG_MU_BF_PART_BW_FDBK, pe->phy_cap_info[3]); ··· 1626 1619 (EHT_PHY(CAP1_BEAMFORMEE_SS_80MHZ_MASK, pe->phy_cap_info[1]) << 1); 1627 1620 bf->nrow = min_t(u8, snd_dim, sts); 1628 1621 bf->ncol = min_t(u8, nss_mcs, bf->nrow); 1629 - bf->ibf_ncol = bf->ncol; 1622 + bf->ibf_ncol = explicit ? min_t(u8, MT7996_IBF_MAX_NC, bf->ncol) : 1623 + min_t(u8, MT7996_IBF_MAX_NC, nss_mcs); 1630 1624 1631 1625 if (sta->deflink.bandwidth < IEEE80211_STA_RX_BW_160) 1632 1626 return; ··· 1662 1654 mt7996_mcu_sta_bfer_tlv(struct mt7996_dev *dev, struct sk_buff *skb, 1663 1655 struct ieee80211_vif *vif, struct ieee80211_sta *sta) 1664 1656 { 1657 + #define EBF_MODE BIT(0) 1658 + #define IBF_MODE BIT(1) 1659 + #define BF_MAT_ORDER 4 1665 1660 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 1666 - struct mt7996_phy *phy = mvif->phy; 1661 + struct mt7996_phy *phy = mvif->deflink.phy; 1667 1662 int tx_ant = hweight16(phy->mt76->chainmask) - 1; 1668 1663 struct sta_rec_bf *bf; 1669 1664 struct tlv *tlv; 1670 - static const u8 matrix[4][4] = { 1665 + static const u8 matrix[BF_MAT_ORDER][BF_MAT_ORDER] = { 1671 1666 {0, 0, 0, 0}, 1672 1667 {1, 1, 0, 0}, /* 2x1, 2x2, 2x3, 2x4 */ 1673 1668 {2, 4, 4, 0}, /* 3x1, 3x2, 3x3, 3x4 */ ··· 1688 1677 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_BF, sizeof(*bf)); 1689 1678 bf = (struct sta_rec_bf *)tlv; 1690 1679 1691 - /* he/eht: eBF only, in accordance with spec 1680 + /* he/eht: eBF only, except mt7992 that has 5T on 5GHz also supports iBF 1692 1681 * vht: support eBF and iBF 1693 1682 * ht: iBF only, since mac80211 lacks of eBF support 1694 1683 */ 1695 - if (sta->deflink.eht_cap.has_eht && ebf) 1696 - mt7996_mcu_sta_bfer_eht(sta, vif, phy, bf); 1697 - else if (sta->deflink.he_cap.has_he && ebf) 1698 - mt7996_mcu_sta_bfer_he(sta, vif, phy, bf); 1684 + if (sta->deflink.eht_cap.has_eht) 1685 + mt7996_mcu_sta_bfer_eht(sta, vif, phy, bf, ebf); 1686 + else if (sta->deflink.he_cap.has_he) 1687 + mt7996_mcu_sta_bfer_he(sta, vif, phy, bf, ebf); 1699 1688 else if (sta->deflink.vht_cap.vht_supported) 1700 1689 mt7996_mcu_sta_bfer_vht(sta, phy, bf, ebf); 1701 1690 else if (sta->deflink.ht_cap.ht_supported) 1702 - mt7996_mcu_sta_bfer_ht(sta, phy, bf); 1691 + mt7996_mcu_sta_bfer_ht(sta, phy, bf, ebf); 1703 1692 else 1704 1693 return; 1705 1694 1706 - bf->bf_cap = ebf ? ebf : dev->ibf << 1; 1695 + bf->bf_cap = ebf ? EBF_MODE : (dev->ibf ? IBF_MODE : 0); 1696 + if (is_mt7992(&dev->mt76) && tx_ant == 4) 1697 + bf->bf_cap |= IBF_MODE; 1707 1698 bf->bw = sta->deflink.bandwidth; 1708 1699 bf->ibf_dbw = sta->deflink.bandwidth; 1709 1700 bf->ibf_nrow = tx_ant; 1710 1701 1711 - if (!ebf && sta->deflink.bandwidth <= IEEE80211_STA_RX_BW_40 && !bf->ncol) 1712 - bf->ibf_timeout = 0x48; 1702 + if (sta->deflink.eht_cap.has_eht || sta->deflink.he_cap.has_he) 1703 + bf->ibf_timeout = is_mt7996(&dev->mt76) ? MT7996_IBF_TIMEOUT : 1704 + MT7992_IBF_TIMEOUT; 1705 + else if (!ebf && sta->deflink.bandwidth <= IEEE80211_STA_RX_BW_40 && !bf->ncol) 1706 + bf->ibf_timeout = MT7996_IBF_TIMEOUT_LEGACY; 1713 1707 else 1714 - bf->ibf_timeout = 0x18; 1708 + bf->ibf_timeout = MT7996_IBF_TIMEOUT; 1715 1709 1716 - if (ebf && bf->nrow != tx_ant) 1717 - bf->mem_20m = matrix[tx_ant][bf->ncol]; 1718 - else 1719 - bf->mem_20m = matrix[bf->nrow][bf->ncol]; 1710 + if (bf->ncol < BF_MAT_ORDER) { 1711 + if (ebf) 1712 + bf->mem_20m = tx_ant < BF_MAT_ORDER ? 1713 + matrix[tx_ant][bf->ncol] : 0; 1714 + else 1715 + bf->mem_20m = bf->nrow < BF_MAT_ORDER ? 1716 + matrix[bf->nrow][bf->ncol] : 0; 1717 + } 1720 1718 1721 1719 switch (sta->deflink.bandwidth) { 1722 1720 case IEEE80211_STA_RX_BW_160: ··· 1746 1726 struct ieee80211_vif *vif, struct ieee80211_sta *sta) 1747 1727 { 1748 1728 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 1749 - struct mt7996_phy *phy = mvif->phy; 1729 + struct mt7996_phy *phy = mvif->deflink.phy; 1750 1730 int tx_ant = hweight8(phy->mt76->antenna_mask) - 1; 1751 1731 struct sta_rec_bfee *bfee; 1752 1732 struct tlv *tlv; ··· 1803 1783 1804 1784 static void 1805 1785 mt7996_mcu_sta_hdr_trans_tlv(struct mt7996_dev *dev, struct sk_buff *skb, 1806 - struct ieee80211_vif *vif, 1807 - struct ieee80211_sta *sta) 1786 + struct ieee80211_vif *vif, struct mt76_wcid *wcid) 1808 1787 { 1809 1788 struct sta_rec_hdr_trans *hdr_trans; 1810 - struct mt76_wcid *wcid; 1811 1789 struct tlv *tlv; 1812 1790 1813 1791 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_HDR_TRANS, sizeof(*hdr_trans)); ··· 1817 1799 else 1818 1800 hdr_trans->from_ds = true; 1819 1801 1820 - if (!sta) 1802 + if (!wcid) 1821 1803 return; 1822 1804 1823 - wcid = (struct mt76_wcid *)sta->drv_priv; 1824 1805 hdr_trans->dis_rx_hdr_tran = !test_bit(MT_WCID_FLAG_HDR_TRANS, &wcid->flags); 1825 1806 if (test_bit(MT_WCID_FLAG_4ADDR, &wcid->flags)) { 1826 1807 hdr_trans->to_ds = true; ··· 1884 1867 struct sk_buff *skb; 1885 1868 struct tlv *tlv; 1886 1869 1887 - skb = __mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76, 1870 + skb = __mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->deflink.mt76, 1888 1871 &msta->wcid, 1889 1872 MT7996_STA_UPDATE_MAX_SIZE); 1890 1873 if (IS_ERR(skb)) ··· 1920 1903 struct ieee80211_sta *sta) 1921 1904 { 1922 1905 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 1923 - struct cfg80211_chan_def *chandef = &mvif->phy->mt76->chandef; 1924 - struct cfg80211_bitrate_mask *mask = &mvif->bitrate_mask; 1906 + struct cfg80211_chan_def *chandef = &mvif->deflink.phy->mt76->chandef; 1907 + struct cfg80211_bitrate_mask *mask = &mvif->deflink.bitrate_mask; 1925 1908 enum nl80211_band band = chandef->chan->band; 1926 1909 struct sta_phy_uni phy = {}; 1927 1910 int ret, nrates = 0; ··· 2008 1991 { 2009 1992 #define INIT_RCPI 180 2010 1993 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 2011 - struct mt76_phy *mphy = mvif->phy->mt76; 1994 + struct mt76_phy *mphy = mvif->deflink.phy->mt76; 2012 1995 struct cfg80211_chan_def *chandef = &mphy->chandef; 2013 - struct cfg80211_bitrate_mask *mask = &mvif->bitrate_mask; 1996 + struct cfg80211_bitrate_mask *mask = &mvif->deflink.bitrate_mask; 2014 1997 enum nl80211_band band = chandef->chan->band; 2015 1998 struct sta_rec_ra_uni *ra; 2016 1999 struct tlv *tlv; ··· 2087 2070 cap |= STA_CAP_VHT_TX_STBC; 2088 2071 if (sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_RXSTBC_1) 2089 2072 cap |= STA_CAP_VHT_RX_STBC; 2090 - if (vif->bss_conf.vht_ldpc && 2073 + if ((vif->type != NL80211_IFTYPE_AP || vif->bss_conf.vht_ldpc) && 2091 2074 (sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_RXLDPC)) 2092 2075 cap |= STA_CAP_VHT_LDPC; 2093 2076 ··· 2116 2099 struct sk_buff *skb; 2117 2100 int ret; 2118 2101 2119 - skb = __mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76, 2102 + skb = __mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->deflink.mt76, 2120 2103 &msta->wcid, 2121 2104 MT7996_STA_UPDATE_MAX_SIZE); 2122 2105 if (IS_ERR(skb)) ··· 2163 2146 .tag = cpu_to_le16(UNI_VOW_DRR_CTRL), 2164 2147 .len = cpu_to_le16(sizeof(req) - 4), 2165 2148 .action = cpu_to_le32(MT_STA_BSS_GROUP), 2166 - .val = cpu_to_le32(mvif->mt76.idx % 16), 2149 + .val = cpu_to_le32(mvif->deflink.mt76.idx % 16), 2167 2150 }; 2168 2151 2169 - msta = sta ? (struct mt7996_sta *)sta->drv_priv : &mvif->sta; 2152 + msta = sta ? (struct mt7996_sta *)sta->drv_priv : &mvif->deflink.sta; 2170 2153 req.wlan_idx = cpu_to_le16(msta->wcid.idx); 2171 2154 2172 2155 return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(VOW), &req, ··· 2174 2157 } 2175 2158 2176 2159 int mt7996_mcu_add_sta(struct mt7996_dev *dev, struct ieee80211_vif *vif, 2177 - struct ieee80211_sta *sta, bool enable, bool newly) 2160 + struct mt76_vif_link *mlink, 2161 + struct ieee80211_sta *sta, int conn_state, bool newly) 2178 2162 { 2179 - struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 2180 - struct ieee80211_link_sta *link_sta; 2181 - struct mt7996_sta *msta; 2163 + struct ieee80211_link_sta *link_sta = NULL; 2164 + struct mt76_wcid *wcid = mlink->wcid; 2182 2165 struct sk_buff *skb; 2183 - int conn_state; 2184 2166 int ret; 2185 2167 2186 - msta = sta ? (struct mt7996_sta *)sta->drv_priv : &mvif->sta; 2187 - link_sta = sta ? &sta->deflink : NULL; 2168 + if (sta) { 2169 + struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; 2188 2170 2189 - skb = __mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76, 2190 - &msta->wcid, 2171 + wcid = &msta->wcid; 2172 + link_sta = &sta->deflink; 2173 + } 2174 + 2175 + skb = __mt76_connac_mcu_alloc_sta_req(&dev->mt76, mlink, wcid, 2191 2176 MT7996_STA_UPDATE_MAX_SIZE); 2192 2177 if (IS_ERR(skb)) 2193 2178 return PTR_ERR(skb); 2194 2179 2195 2180 /* starec basic */ 2196 - conn_state = enable ? CONN_STATE_PORT_SECURE : CONN_STATE_DISCONNECT; 2197 - mt76_connac_mcu_sta_basic_tlv(&dev->mt76, skb, vif, link_sta, 2181 + mt76_connac_mcu_sta_basic_tlv(&dev->mt76, skb, &vif->bss_conf, link_sta, 2198 2182 conn_state, newly); 2199 2183 2200 - if (!enable) 2184 + if (conn_state == CONN_STATE_DISCONNECT) 2201 2185 goto out; 2202 2186 2203 2187 /* starec hdr trans */ 2204 - mt7996_mcu_sta_hdr_trans_tlv(dev, skb, vif, sta); 2188 + mt7996_mcu_sta_hdr_trans_tlv(dev, skb, vif, wcid); 2205 2189 /* starec tx proc */ 2206 2190 mt7996_mcu_sta_tx_proc_tlv(skb); 2207 2191 ··· 2291 2273 struct ieee80211_key_conf *key, int mcu_cmd, 2292 2274 struct mt76_wcid *wcid, enum set_key_cmd cmd) 2293 2275 { 2294 - struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 2276 + struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; 2295 2277 struct sk_buff *skb; 2296 2278 int ret; 2297 2279 ··· 2317 2299 struct tlv *tlv; 2318 2300 int ret; 2319 2301 2320 - skb = mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76, &mvif->sta.wcid); 2302 + skb = mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->deflink.mt76, &mvif->deflink.sta.wcid); 2321 2303 if (IS_ERR(skb)) 2322 2304 return PTR_ERR(skb); 2323 2305 ··· 2353 2335 sizeof(struct mt7996_mcu_bcn_prot_tlv); 2354 2336 int ret; 2355 2337 2356 - skb = __mt7996_mcu_alloc_bss_req(&dev->mt76, &mvif->mt76, len); 2338 + skb = __mt7996_mcu_alloc_bss_req(&dev->mt76, &mvif->deflink.mt76, len); 2357 2339 if (IS_ERR(skb)) 2358 2340 return PTR_ERR(skb); 2359 2341 ··· 2393 2375 return mt76_mcu_skb_send_msg(&dev->mt76, skb, 2394 2376 MCU_WMWA_UNI_CMD(BSS_INFO_UPDATE), true); 2395 2377 } 2396 - int mt7996_mcu_add_dev_info(struct mt7996_phy *phy, 2397 - struct ieee80211_vif *vif, bool enable) 2378 + 2379 + int mt7996_mcu_add_dev_info(struct mt7996_phy *phy, struct ieee80211_vif *vif, 2380 + struct ieee80211_bss_conf *link_conf, 2381 + struct mt76_vif_link *mlink, bool enable) 2398 2382 { 2399 2383 struct mt7996_dev *dev = phy->dev; 2400 - struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 2401 2384 struct { 2402 2385 struct req_hdr { 2403 2386 u8 omac_idx; ··· 2414 2395 } __packed tlv; 2415 2396 } data = { 2416 2397 .hdr = { 2417 - .omac_idx = mvif->mt76.omac_idx, 2418 - .band_idx = mvif->mt76.band_idx, 2398 + .omac_idx = mlink->omac_idx, 2399 + .band_idx = mlink->band_idx, 2419 2400 }, 2420 2401 .tlv = { 2421 2402 .tag = cpu_to_le16(DEV_INFO_ACTIVE), ··· 2424 2405 }, 2425 2406 }; 2426 2407 2427 - if (mvif->mt76.omac_idx >= REPEATER_BSSID_START) 2428 - return mt7996_mcu_muar_config(phy, vif, false, enable); 2408 + if (mlink->omac_idx >= REPEATER_BSSID_START) 2409 + return mt7996_mcu_muar_config(dev, mlink, link_conf->addr, false, enable); 2429 2410 2430 - memcpy(data.tlv.omac_addr, vif->addr, ETH_ALEN); 2411 + memcpy(data.tlv.omac_addr, link_conf->addr, ETH_ALEN); 2431 2412 return mt76_mcu_send_msg(&dev->mt76, MCU_WMWA_UNI_CMD(DEV_INFO_UPDATE), 2432 2413 &data, sizeof(data), true); 2433 2414 } 2434 2415 2435 2416 static void 2436 - mt7996_mcu_beacon_cntdwn(struct ieee80211_vif *vif, struct sk_buff *rskb, 2437 - struct sk_buff *skb, 2438 - struct ieee80211_mutable_offsets *offs) 2417 + mt7996_mcu_beacon_cntdwn(struct sk_buff *rskb, struct sk_buff *skb, 2418 + struct ieee80211_mutable_offsets *offs, 2419 + bool csa) 2439 2420 { 2440 2421 struct bss_bcn_cntdwn_tlv *info; 2441 2422 struct tlv *tlv; ··· 2444 2425 if (!offs->cntdwn_counter_offs[0]) 2445 2426 return; 2446 2427 2447 - tag = vif->bss_conf.csa_active ? UNI_BSS_INFO_BCN_CSA : UNI_BSS_INFO_BCN_BCC; 2428 + tag = csa ? UNI_BSS_INFO_BCN_CSA : UNI_BSS_INFO_BCN_BCC; 2448 2429 2449 2430 tlv = mt7996_mcu_add_uni_tlv(rskb, tag, sizeof(*info)); 2450 2431 ··· 2454 2435 2455 2436 static void 2456 2437 mt7996_mcu_beacon_mbss(struct sk_buff *rskb, struct sk_buff *skb, 2457 - struct ieee80211_vif *vif, struct bss_bcn_content_tlv *bcn, 2438 + struct bss_bcn_content_tlv *bcn, 2458 2439 struct ieee80211_mutable_offsets *offs) 2459 2440 { 2460 2441 struct bss_bcn_mbss_tlv *mbss; 2461 2442 const struct element *elem; 2462 2443 struct tlv *tlv; 2463 - 2464 - if (!vif->bss_conf.bssid_indicator) 2465 - return; 2466 2444 2467 2445 tlv = mt7996_mcu_add_uni_tlv(rskb, UNI_BSS_INFO_BCN_MBSSID, sizeof(*mbss)); 2468 2446 ··· 2503 2487 } 2504 2488 2505 2489 static void 2506 - mt7996_mcu_beacon_cont(struct mt7996_dev *dev, struct ieee80211_vif *vif, 2490 + mt7996_mcu_beacon_cont(struct mt7996_dev *dev, 2491 + struct ieee80211_bss_conf *link_conf, 2507 2492 struct sk_buff *rskb, struct sk_buff *skb, 2508 2493 struct bss_bcn_content_tlv *bcn, 2509 2494 struct ieee80211_mutable_offsets *offs) ··· 2518 2501 if (offs->cntdwn_counter_offs[0]) { 2519 2502 u16 offset = offs->cntdwn_counter_offs[0]; 2520 2503 2521 - if (vif->bss_conf.csa_active) 2504 + if (link_conf->csa_active) 2522 2505 bcn->csa_ie_pos = cpu_to_le16(offset - 4); 2523 - if (vif->bss_conf.color_change_active) 2506 + if (link_conf->color_change_active) 2524 2507 bcn->bcc_ie_pos = cpu_to_le16(offset - 3); 2525 2508 } 2526 2509 ··· 2531 2514 memcpy(buf + MT_TXD_SIZE, skb->data, skb->len); 2532 2515 } 2533 2516 2534 - int mt7996_mcu_add_beacon(struct ieee80211_hw *hw, 2535 - struct ieee80211_vif *vif, int en) 2517 + int mt7996_mcu_add_beacon(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 2518 + struct ieee80211_bss_conf *link_conf) 2536 2519 { 2537 2520 struct mt7996_dev *dev = mt7996_hw_dev(hw); 2538 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 2539 - struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 2521 + struct mt76_vif_link *mlink = mt76_vif_conf_link(&dev->mt76, vif, link_conf); 2540 2522 struct ieee80211_mutable_offsets offs; 2541 2523 struct ieee80211_tx_info *info; 2542 2524 struct sk_buff *skb, *rskb; 2543 2525 struct tlv *tlv; 2544 2526 struct bss_bcn_content_tlv *bcn; 2545 - int len; 2527 + int len, extra_len = 0; 2546 2528 2547 - if (vif->bss_conf.nontransmitted) 2529 + if (link_conf->nontransmitted) 2548 2530 return 0; 2549 2531 2550 - rskb = __mt7996_mcu_alloc_bss_req(&dev->mt76, &mvif->mt76, 2532 + if (!mlink) 2533 + return -EINVAL; 2534 + 2535 + rskb = __mt7996_mcu_alloc_bss_req(&dev->mt76, mlink, 2551 2536 MT7996_MAX_BSS_OFFLOAD_SIZE); 2552 2537 if (IS_ERR(rskb)) 2553 2538 return PTR_ERR(rskb); 2554 2539 2555 - skb = ieee80211_beacon_get_template(hw, vif, &offs, 0); 2556 - if (!skb) { 2540 + skb = ieee80211_beacon_get_template(hw, vif, &offs, link_conf->link_id); 2541 + if (link_conf->enable_beacon && !skb) { 2557 2542 dev_kfree_skb(rskb); 2558 2543 return -EINVAL; 2559 2544 } 2560 2545 2561 - if (skb->len > MT7996_MAX_BEACON_SIZE) { 2562 - dev_err(dev->mt76.dev, "Bcn size limit exceed\n"); 2563 - dev_kfree_skb(rskb); 2564 - dev_kfree_skb(skb); 2565 - return -EINVAL; 2546 + if (skb) { 2547 + if (skb->len > MT7996_MAX_BEACON_SIZE) { 2548 + dev_err(dev->mt76.dev, "Bcn size limit exceed\n"); 2549 + dev_kfree_skb(rskb); 2550 + dev_kfree_skb(skb); 2551 + return -EINVAL; 2552 + } 2553 + 2554 + extra_len = skb->len; 2566 2555 } 2567 2556 2568 - info = IEEE80211_SKB_CB(skb); 2569 - info->hw_queue |= FIELD_PREP(MT_TX_HW_QUEUE_PHY, phy->mt76->band_idx); 2570 - 2571 - len = ALIGN(sizeof(*bcn) + MT_TXD_SIZE + skb->len, 4); 2557 + len = ALIGN(sizeof(*bcn) + MT_TXD_SIZE + extra_len, 4); 2572 2558 tlv = mt7996_mcu_add_uni_tlv(rskb, UNI_BSS_INFO_BCN_CONTENT, len); 2573 2559 bcn = (struct bss_bcn_content_tlv *)tlv; 2574 - bcn->enable = en; 2575 - if (!en) 2560 + bcn->enable = link_conf->enable_beacon; 2561 + if (!bcn->enable) 2576 2562 goto out; 2577 2563 2578 - mt7996_mcu_beacon_cont(dev, vif, rskb, skb, bcn, &offs); 2579 - mt7996_mcu_beacon_mbss(rskb, skb, vif, bcn, &offs); 2580 - mt7996_mcu_beacon_cntdwn(vif, rskb, skb, &offs); 2564 + info = IEEE80211_SKB_CB(skb); 2565 + info->hw_queue |= FIELD_PREP(MT_TX_HW_QUEUE_PHY, mlink->band_idx); 2566 + 2567 + mt7996_mcu_beacon_cont(dev, link_conf, rskb, skb, bcn, &offs); 2568 + if (link_conf->bssid_indicator) 2569 + mt7996_mcu_beacon_mbss(rskb, skb, bcn, &offs); 2570 + mt7996_mcu_beacon_cntdwn(rskb, skb, &offs, link_conf->csa_active); 2581 2571 out: 2582 2572 dev_kfree_skb(skb); 2583 - return mt76_mcu_skb_send_msg(&phy->dev->mt76, rskb, 2573 + return mt76_mcu_skb_send_msg(&dev->mt76, rskb, 2584 2574 MCU_WMWA_UNI_CMD(BSS_INFO_UPDATE), true); 2585 2575 } 2586 2576 ··· 2597 2573 #define OFFLOAD_TX_MODE_SU BIT(0) 2598 2574 #define OFFLOAD_TX_MODE_MU BIT(1) 2599 2575 struct ieee80211_hw *hw = mt76_hw(dev); 2600 - struct mt7996_phy *phy = mt7996_hw_phy(hw); 2601 2576 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 2602 - struct cfg80211_chan_def *chandef = &mvif->phy->mt76->chandef; 2603 - enum nl80211_band band = chandef->chan->band; 2577 + struct mt7996_phy *phy = mt7996_vif_link_phy(&mvif->deflink); 2604 2578 struct mt76_wcid *wcid = &dev->mt76.global_wcid; 2605 2579 struct bss_inband_discovery_tlv *discov; 2606 2580 struct ieee80211_tx_info *info; 2607 2581 struct sk_buff *rskb, *skb = NULL; 2582 + struct cfg80211_chan_def *chandef; 2583 + enum nl80211_band band; 2608 2584 struct tlv *tlv; 2609 2585 u8 *buf, interval; 2610 2586 int len; 2611 2587 2588 + if (!phy) 2589 + return -EINVAL; 2590 + 2591 + chandef = &phy->mt76->chandef; 2592 + band = chandef->chan->band; 2593 + 2612 2594 if (vif->bss_conf.nontransmitted) 2613 2595 return 0; 2614 2596 2615 - rskb = __mt7996_mcu_alloc_bss_req(&dev->mt76, &mvif->mt76, 2597 + rskb = __mt7996_mcu_alloc_bss_req(&dev->mt76, &mvif->deflink.mt76, 2616 2598 MT7996_MAX_BSS_OFFLOAD_SIZE); 2617 2599 if (IS_ERR(rskb)) 2618 2600 return PTR_ERR(rskb); ··· 3177 3147 MCU_WM_UNI_CMD(RX_HDR_TRANS), true); 3178 3148 } 3179 3149 3180 - int mt7996_mcu_set_tx(struct mt7996_dev *dev, struct ieee80211_vif *vif) 3150 + int mt7996_mcu_set_tx(struct mt7996_dev *dev, struct ieee80211_vif *vif, 3151 + struct ieee80211_bss_conf *link_conf) 3181 3152 { 3182 3153 #define MCU_EDCA_AC_PARAM 0 3183 3154 #define WMM_AIFS_SET BIT(0) ··· 3187 3156 #define WMM_TXOP_SET BIT(3) 3188 3157 #define WMM_PARAM_SET (WMM_AIFS_SET | WMM_CW_MIN_SET | \ 3189 3158 WMM_CW_MAX_SET | WMM_TXOP_SET) 3190 - struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 3159 + struct mt7996_vif_link *link = mt7996_vif_conf_link(dev, vif, link_conf); 3191 3160 struct { 3192 3161 u8 bss_idx; 3193 3162 u8 __rsv[3]; 3194 3163 } __packed hdr = { 3195 - .bss_idx = mvif->mt76.idx, 3164 + .bss_idx = link->mt76.idx, 3196 3165 }; 3197 3166 struct sk_buff *skb; 3198 3167 int len = sizeof(hdr) + IEEE80211_NUM_ACS * sizeof(struct edca); ··· 3205 3174 skb_put_data(skb, &hdr, sizeof(hdr)); 3206 3175 3207 3176 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 3208 - struct ieee80211_tx_queue_params *q = &mvif->queue_params[ac]; 3177 + struct ieee80211_tx_queue_params *q = &link->queue_params[ac]; 3209 3178 struct edca *e; 3210 3179 struct tlv *tlv; 3211 3180 ··· 3579 3548 &req, sizeof(req), true); 3580 3549 } 3581 3550 3582 - int mt7996_mcu_get_eeprom(struct mt7996_dev *dev, u32 offset) 3551 + int mt7996_mcu_get_eeprom(struct mt7996_dev *dev, u32 offset, u8 *buf, u32 buf_len) 3583 3552 { 3584 3553 struct { 3585 3554 u8 _rsv[4]; ··· 3608 3577 valid = le32_to_cpu(*(__le32 *)(skb->data + 16)); 3609 3578 if (valid) { 3610 3579 u32 addr = le32_to_cpu(*(__le32 *)(skb->data + 12)); 3611 - u8 *buf = (u8 *)dev->mt76.eeprom.data + addr; 3580 + 3581 + if (!buf) 3582 + buf = (u8 *)dev->mt76.eeprom.data + addr; 3583 + if (!buf_len || buf_len > MT7996_EEPROM_BLOCK_SIZE) 3584 + buf_len = MT7996_EEPROM_BLOCK_SIZE; 3612 3585 3613 3586 skb_pull(skb, 48); 3614 - memcpy(buf, skb->data, MT7996_EEPROM_BLOCK_SIZE); 3587 + memcpy(buf, skb->data, buf_len); 3588 + } else { 3589 + ret = -EINVAL; 3615 3590 } 3616 3591 3617 3592 dev_kfree_skb(skb); 3618 3593 3619 - return 0; 3594 + return ret; 3620 3595 } 3621 3596 3622 3597 int mt7996_mcu_get_eeprom_free_block(struct mt7996_dev *dev, u8 *block_num) ··· 3703 3666 3704 3667 int mt7996_mcu_get_chan_mib_info(struct mt7996_phy *phy, bool chan_switch) 3705 3668 { 3669 + enum { 3670 + IDX_TX_TIME, 3671 + IDX_RX_TIME, 3672 + IDX_OBSS_AIRTIME, 3673 + IDX_NON_WIFI_TIME, 3674 + IDX_NUM 3675 + }; 3706 3676 struct { 3707 3677 struct { 3708 3678 u8 band; ··· 3719 3675 __le16 tag; 3720 3676 __le16 len; 3721 3677 __le32 offs; 3722 - } data[4]; 3678 + } data[IDX_NUM]; 3723 3679 } __packed req = { 3724 3680 .hdr.band = phy->mt76->band_idx, 3725 3681 }; 3726 - /* strict order */ 3727 3682 static const u32 offs[] = { 3728 - UNI_MIB_TX_TIME, 3729 - UNI_MIB_RX_TIME, 3730 - UNI_MIB_OBSS_AIRTIME, 3731 - UNI_MIB_NON_WIFI_TIME, 3683 + [IDX_TX_TIME] = UNI_MIB_TX_TIME, 3684 + [IDX_RX_TIME] = UNI_MIB_RX_TIME, 3685 + [IDX_OBSS_AIRTIME] = UNI_MIB_OBSS_AIRTIME, 3686 + [IDX_NON_WIFI_TIME] = UNI_MIB_NON_WIFI_TIME, 3732 3687 }; 3733 3688 struct mt76_channel_state *state = phy->mt76->chan_state; 3734 3689 struct mt76_channel_state *state_ts = &phy->state_ts; ··· 3736 3693 struct sk_buff *skb; 3737 3694 int i, ret; 3738 3695 3739 - for (i = 0; i < 4; i++) { 3696 + for (i = 0; i < IDX_NUM; i++) { 3740 3697 req.data[i].tag = cpu_to_le16(UNI_CMD_MIB_DATA); 3741 3698 req.data[i].len = cpu_to_le16(sizeof(req.data[i])); 3742 3699 req.data[i].offs = cpu_to_le32(offs[i]); ··· 3755 3712 goto out; 3756 3713 3757 3714 #define __res_u64(s) le64_to_cpu(res[s].data) 3758 - state->cc_tx += __res_u64(1) - state_ts->cc_tx; 3759 - state->cc_bss_rx += __res_u64(2) - state_ts->cc_bss_rx; 3760 - state->cc_rx += __res_u64(2) + __res_u64(3) - state_ts->cc_rx; 3761 - state->cc_busy += __res_u64(0) + __res_u64(1) + __res_u64(2) + __res_u64(3) - 3715 + state->cc_tx += __res_u64(IDX_TX_TIME) - state_ts->cc_tx; 3716 + state->cc_bss_rx += __res_u64(IDX_RX_TIME) - state_ts->cc_bss_rx; 3717 + state->cc_rx += __res_u64(IDX_RX_TIME) + 3718 + __res_u64(IDX_OBSS_AIRTIME) - 3719 + state_ts->cc_rx; 3720 + state->cc_busy += __res_u64(IDX_TX_TIME) + 3721 + __res_u64(IDX_RX_TIME) + 3722 + __res_u64(IDX_OBSS_AIRTIME) + 3723 + __res_u64(IDX_NON_WIFI_TIME) - 3762 3724 state_ts->cc_busy; 3763 - 3764 3725 out: 3765 - state_ts->cc_tx = __res_u64(1); 3766 - state_ts->cc_bss_rx = __res_u64(2); 3767 - state_ts->cc_rx = __res_u64(2) + __res_u64(3); 3768 - state_ts->cc_busy = __res_u64(0) + __res_u64(1) + __res_u64(2) + __res_u64(3); 3726 + state_ts->cc_tx = __res_u64(IDX_TX_TIME); 3727 + state_ts->cc_bss_rx = __res_u64(IDX_RX_TIME); 3728 + state_ts->cc_rx = __res_u64(IDX_RX_TIME) + __res_u64(IDX_OBSS_AIRTIME); 3729 + state_ts->cc_busy = __res_u64(IDX_TX_TIME) + 3730 + __res_u64(IDX_RX_TIME) + 3731 + __res_u64(IDX_OBSS_AIRTIME) + 3732 + __res_u64(IDX_NON_WIFI_TIME); 3769 3733 #undef __res_u64 3770 3734 3771 3735 dev_kfree_skb(skb); ··· 4073 4023 { 4074 4024 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 4075 4025 struct mt7996_dev *dev = phy->dev; 4076 - u8 omac = mvif->mt76.omac_idx; 4026 + u8 omac = mvif->deflink.mt76.omac_idx; 4077 4027 struct { 4078 4028 u8 band_idx; 4079 4029 u8 __rsv[3]; ··· 4187 4137 return mt7996_mcu_set_obss_spr_bitmap(phy, he_obss_pd); 4188 4138 } 4189 4139 4190 - int mt7996_mcu_update_bss_color(struct mt7996_dev *dev, struct ieee80211_vif *vif, 4140 + int mt7996_mcu_update_bss_color(struct mt7996_dev *dev, 4141 + struct mt76_vif_link *mlink, 4191 4142 struct cfg80211_he_bss_color *he_bss_color) 4192 4143 { 4193 4144 int len = sizeof(struct bss_req_hdr) + sizeof(struct bss_color_tlv); 4194 - struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; 4195 4145 struct bss_color_tlv *bss_color; 4196 4146 struct sk_buff *skb; 4197 4147 struct tlv *tlv; 4198 4148 4199 - skb = __mt7996_mcu_alloc_bss_req(&dev->mt76, &mvif->mt76, len); 4149 + skb = __mt7996_mcu_alloc_bss_req(&dev->mt76, mlink, len); 4200 4150 if (IS_ERR(skb)) 4201 4151 return PTR_ERR(skb); 4202 4152 ··· 4246 4196 .len = cpu_to_le16(sizeof(req) - 4), 4247 4197 .tbl_idx = flow->table_id, 4248 4198 .cmd = cmd, 4249 - .own_mac_idx = mvif->mt76.omac_idx, 4199 + .own_mac_idx = mvif->deflink.mt76.omac_idx, 4250 4200 .flowid = flow->id, 4251 4201 .peer_id = cpu_to_le16(flow->wcid), 4252 4202 .duration = flow->duration, 4253 - .bss = mvif->mt76.idx, 4254 - .bss_idx = mvif->mt76.idx, 4203 + .bss = mvif->deflink.mt76.idx, 4204 + .bss_idx = mvif->deflink.mt76.idx, 4255 4205 .start_tsf = cpu_to_le64(flow->tsf), 4256 4206 .mantissa = flow->mantissa, 4257 4207 .exponent = flow->exp, ··· 4347 4297 struct mt7996_sta *msta; 4348 4298 struct sk_buff *skb; 4349 4299 4350 - msta = sta ? (struct mt7996_sta *)sta->drv_priv : &mvif->sta; 4300 + msta = sta ? (struct mt7996_sta *)sta->drv_priv : &mvif->deflink.sta; 4351 4301 4352 - skb = __mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76, 4302 + skb = __mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->deflink.mt76, 4353 4303 &msta->wcid, 4354 4304 MT7996_STA_UPDATE_MAX_SIZE); 4355 4305 if (IS_ERR(skb)) 4356 4306 return PTR_ERR(skb); 4357 4307 4358 4308 /* starec hdr trans */ 4359 - mt7996_mcu_sta_hdr_trans_tlv(dev, skb, vif, sta); 4309 + mt7996_mcu_sta_hdr_trans_tlv(dev, skb, vif, &msta->wcid); 4360 4310 return mt76_mcu_skb_send_msg(&dev->mt76, skb, 4361 4311 MCU_WMWA_UNI_CMD(STA_REC_UPDATE), true); 4362 4312 } ··· 4534 4484 sizeof(req), true); 4535 4485 } 4536 4486 4487 + int mt7996_mcu_set_sniffer_mode(struct mt7996_phy *phy, bool enabled) 4488 + { 4489 + struct mt7996_dev *dev = phy->dev; 4490 + struct { 4491 + u8 band_idx; 4492 + u8 _rsv[3]; 4493 + __le16 tag; 4494 + __le16 len; 4495 + u8 enable; 4496 + u8 _pad[3]; 4497 + } __packed req = { 4498 + .band_idx = phy->mt76->band_idx, 4499 + .tag = 0, 4500 + .len = cpu_to_le16(sizeof(req) - 4), 4501 + .enable = enabled, 4502 + }; 4503 + 4504 + return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(SNIFFER), &req, 4505 + sizeof(req), true); 4506 + } 4507 + 4537 4508 int mt7996_mcu_set_txpower_sku(struct mt7996_phy *phy) 4538 4509 { 4539 4510 #define TX_POWER_LIMIT_TABLE_RATE 0 4540 4511 struct mt7996_dev *dev = phy->dev; 4541 4512 struct mt76_phy *mphy = phy->mt76; 4542 - struct ieee80211_hw *hw = mphy->hw; 4543 4513 struct tx_power_limit_table_ctrl { 4544 4514 u8 __rsv1[4]; 4545 4515 ··· 4579 4509 struct sk_buff *skb; 4580 4510 int i, tx_power; 4581 4511 4582 - tx_power = mt7996_get_power_bound(phy, hw->conf.power_level); 4512 + tx_power = mt7996_get_power_bound(phy, phy->txpower); 4583 4513 tx_power = mt76_get_rate_power_limits(mphy, mphy->chandef.chan, 4584 4514 &la, tx_power); 4585 4515 mphy->txpower_cur = tx_power;
+5 -1
drivers/net/wireless/mediatek/mt76/mt7996/mmio.c
··· 177 177 continue; 178 178 179 179 ofs = addr - dev->reg.map[i].phys; 180 - if (ofs > dev->reg.map[i].size) 180 + if (ofs >= dev->reg.map[i].size) 181 181 continue; 182 182 183 183 return dev->reg.map[i].mapped + ofs; ··· 605 605 static const struct mt76_driver_ops drv_ops = { 606 606 /* txwi_size = txd size + txp size */ 607 607 .txwi_size = MT_TXD_SIZE + sizeof(struct mt76_connac_fw_txp), 608 + .link_data_size = sizeof(struct mt7996_vif_link), 608 609 .drv_flags = MT_DRV_TXWI_NO_FREE | 609 610 MT_DRV_AMSDU_OFFLOAD | 610 611 MT_DRV_HW_MGMT_TXQ, ··· 619 618 .rx_check = mt7996_rx_check, 620 619 .rx_poll_complete = mt7996_rx_poll_complete, 621 620 .sta_add = mt7996_mac_sta_add, 621 + .sta_event = mt7996_mac_sta_event, 622 622 .sta_remove = mt7996_mac_sta_remove, 623 623 .update_survey = mt7996_update_channel, 624 624 .set_channel = mt7996_set_channel, 625 + .vif_link_add = mt7996_vif_link_add, 626 + .vif_link_remove = mt7996_vif_link_remove, 625 627 }; 626 628 struct mt7996_dev *dev; 627 629 struct mt76_dev *mdev;
+149 -30
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
··· 11 11 #include "../mt76_connac.h" 12 12 #include "regs.h" 13 13 14 + #define MT7996_MAX_RADIOS 3 14 15 #define MT7996_MAX_INTERFACES 19 /* per-band */ 15 16 #define MT7996_MAX_WMM_SETS 4 16 17 #define MT7996_WTBL_BMC_SIZE (is_mt7992(&dev->mt76) ? 32 : 64) ··· 35 34 #define MT7996_FIRMWARE_DSP "mediatek/mt7996/mt7996_dsp.bin" 36 35 #define MT7996_ROM_PATCH "mediatek/mt7996/mt7996_rom_patch.bin" 37 36 37 + #define MT7996_FIRMWARE_WA_233 "mediatek/mt7996/mt7996_wa_233.bin" 38 + #define MT7996_FIRMWARE_WM_233 "mediatek/mt7996/mt7996_wm_233.bin" 39 + #define MT7996_FIRMWARE_DSP_233 MT7996_FIRMWARE_DSP 40 + #define MT7996_ROM_PATCH_233 "mediatek/mt7996/mt7996_rom_patch_233.bin" 41 + 38 42 #define MT7992_FIRMWARE_WA "mediatek/mt7996/mt7992_wa.bin" 39 43 #define MT7992_FIRMWARE_WM "mediatek/mt7996/mt7992_wm.bin" 40 44 #define MT7992_FIRMWARE_DSP "mediatek/mt7996/mt7992_dsp.bin" 41 45 #define MT7992_ROM_PATCH "mediatek/mt7996/mt7992_rom_patch.bin" 42 46 47 + #define MT7992_FIRMWARE_WA_23 "mediatek/mt7996/mt7992_wa_23.bin" 48 + #define MT7992_FIRMWARE_WM_23 "mediatek/mt7996/mt7992_wm_23.bin" 49 + #define MT7992_FIRMWARE_DSP_23 "mediatek/mt7996/mt7992_dsp_23.bin" 50 + #define MT7992_ROM_PATCH_23 "mediatek/mt7996/mt7992_rom_patch_23.bin" 51 + 43 52 #define MT7996_EEPROM_DEFAULT "mediatek/mt7996/mt7996_eeprom.bin" 53 + #define MT7996_EEPROM_DEFAULT_INT "mediatek/mt7996/mt7996_eeprom_2i5i6i.bin" 54 + #define MT7996_EEPROM_DEFAULT_233 "mediatek/mt7996/mt7996_eeprom_233.bin" 55 + #define MT7996_EEPROM_DEFAULT_233_INT "mediatek/mt7996/mt7996_eeprom_233_2i5i6i.bin" 56 + 44 57 #define MT7992_EEPROM_DEFAULT "mediatek/mt7996/mt7992_eeprom.bin" 58 + #define MT7992_EEPROM_DEFAULT_INT "mediatek/mt7996/mt7992_eeprom_2i5i.bin" 59 + #define MT7992_EEPROM_DEFAULT_MIX "mediatek/mt7996/mt7992_eeprom_2i5e.bin" 60 + #define MT7992_EEPROM_DEFAULT_23 "mediatek/mt7996/mt7992_eeprom_23.bin" 61 + #define MT7992_EEPROM_DEFAULT_23_INT "mediatek/mt7996/mt7992_eeprom_23_2i5i.bin" 62 + 45 63 #define MT7996_EEPROM_SIZE 7680 46 64 #define MT7996_EEPROM_BLOCK_SIZE 16 47 65 #define MT7996_TOKEN_SIZE 16384 ··· 68 48 69 49 #define MT7996_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */ 70 50 #define MT7996_CFEND_RATE_11B 0x03 /* 11B LP, 11M */ 51 + #define MT7996_IBF_MAX_NC 2 52 + #define MT7996_IBF_TIMEOUT 0x18 53 + #define MT7996_IBF_TIMEOUT_LEGACY 0x48 54 + 55 + #define MT7992_CFEND_RATE_DEFAULT 0x4b /* OFDM 6M */ 56 + #define MT7992_IBF_TIMEOUT 0xff 71 57 72 58 #define MT7996_SKU_RATE_NUM 417 73 59 #define MT7996_SKU_PATH_NUM 494 ··· 119 93 MT7996_RAM_TYPE_WM, 120 94 MT7996_RAM_TYPE_WA, 121 95 MT7996_RAM_TYPE_DSP, 96 + }; 97 + 98 + enum mt7996_var_type { 99 + MT7996_VAR_TYPE_444, 100 + MT7996_VAR_TYPE_233, 101 + }; 102 + 103 + enum mt7992_var_type { 104 + MT7992_VAR_TYPE_44, 105 + MT7992_VAR_TYPE_23, 106 + }; 107 + 108 + enum mt7996_fem_type { 109 + MT7996_FEM_EXT, 110 + MT7996_FEM_INT, 111 + MT7996_FEM_MIX, 122 112 }; 123 113 124 114 enum mt7996_txq_id { ··· 206 164 } twt; 207 165 }; 208 166 209 - struct mt7996_vif { 210 - struct mt76_vif mt76; /* must be first */ 167 + struct mt7996_vif_link { 168 + struct mt76_vif_link mt76; /* must be first */ 211 169 212 170 struct mt7996_sta sta; 213 171 struct mt7996_phy *phy; 214 172 215 173 struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS]; 216 174 struct cfg80211_bitrate_mask bitrate_mask; 175 + }; 176 + 177 + struct mt7996_vif { 178 + struct mt7996_vif_link deflink; /* must be first */ 179 + struct mt76_vif_data mt76; 217 180 }; 218 181 219 182 /* crash-dump */ ··· 258 211 259 212 struct ieee80211_sband_iftype_data iftype[NUM_NL80211_BANDS][NUM_NL80211_IFTYPES]; 260 213 261 - struct ieee80211_vif *monitor_vif; 262 - 263 214 struct thermal_cooling_device *cdev; 264 215 u8 cdev_state; 265 216 u8 throttle_state; ··· 277 232 278 233 u32 rx_ampdu_ts; 279 234 u32 ampdu_ref; 235 + int txpower; 280 236 281 237 struct mt76_mib_stats mib; 282 238 struct mt76_channel_state state_ts; 283 239 240 + u16 orig_chainmask; 241 + 284 242 bool has_aux_rx; 243 + bool counter_reset; 285 244 }; 286 245 287 246 struct mt7996_dev { ··· 293 244 struct mt76_dev mt76; 294 245 struct mt76_phy mphy; 295 246 }; 247 + 248 + struct mt7996_phy *radio_phy[MT7996_MAX_RADIOS]; 249 + struct wiphy_radio radios[MT7996_MAX_RADIOS]; 250 + struct wiphy_radio_freq_range radio_freqs[MT7996_MAX_RADIOS]; 296 251 297 252 struct mt7996_hif *hif2; 298 253 struct mt7996_reg_desc reg; ··· 382 329 spinlock_t reg_lock; 383 330 384 331 u8 wtbl_size_group; 332 + struct { 333 + u8 type:4; 334 + u8 fem:4; 335 + } var; 385 336 }; 386 337 387 338 enum { ··· 416 359 RDD_RESUME_BF, 417 360 RDD_IRQ_OFF, 418 361 }; 419 - 420 - static inline struct mt7996_phy * 421 - mt7996_hw_phy(struct ieee80211_hw *hw) 422 - { 423 - struct mt76_phy *phy = hw->priv; 424 - 425 - return phy->priv; 426 - } 427 362 428 363 static inline struct mt7996_dev * 429 364 mt7996_hw_dev(struct ieee80211_hw *hw) ··· 454 405 if (is_mt7992(&dev->mt76)) 455 406 return band <= MT_BAND1; 456 407 457 - /* tri-band support */ 458 - if (band <= MT_BAND2 && 459 - mt76_get_field(dev, MT_PAD_GPIO, MT_PAD_GPIO_ADIE_COMB) <= 1) 460 - return true; 461 - 462 - return band == MT_BAND0 || band == MT_BAND2; 408 + return band <= MT_BAND2; 463 409 } 410 + 411 + static inline bool 412 + mt7996_has_background_radar(struct mt7996_dev *dev) 413 + { 414 + switch (mt76_chip(&dev->mt76)) { 415 + case 0x7990: 416 + if (dev->var.type == MT7996_VAR_TYPE_233) 417 + return false; 418 + break; 419 + case 0x7992: 420 + if (dev->var.type == MT7992_VAR_TYPE_23) 421 + return false; 422 + break; 423 + default: 424 + return false; 425 + } 426 + 427 + return true; 428 + } 429 + 430 + static inline struct mt7996_phy * 431 + mt7996_band_phy(struct mt7996_dev *dev, enum nl80211_band band) 432 + { 433 + struct mt76_phy *mphy; 434 + 435 + mphy = dev->mt76.band_phys[band]; 436 + if (!mphy) 437 + return NULL; 438 + 439 + return mphy->priv; 440 + } 441 + 442 + static inline struct mt7996_vif_link * 443 + mt7996_vif_link(struct mt7996_dev *dev, struct ieee80211_vif *vif, int link_id) 444 + { 445 + return (struct mt7996_vif_link *)mt76_vif_link(&dev->mt76, vif, link_id); 446 + } 447 + 448 + static inline struct mt7996_phy * 449 + mt7996_vif_link_phy(struct mt7996_vif_link *link) 450 + { 451 + struct mt76_phy *mphy = mt76_vif_link_phy(&link->mt76); 452 + 453 + if (!mphy) 454 + return NULL; 455 + 456 + return mphy->priv; 457 + } 458 + 459 + static inline struct mt7996_vif_link * 460 + mt7996_vif_conf_link(struct mt7996_dev *dev, struct ieee80211_vif *vif, 461 + struct ieee80211_bss_conf *link_conf) 462 + { 463 + return (struct mt7996_vif_link *)mt76_vif_conf_link(&dev->mt76, vif, 464 + link_conf); 465 + } 466 + 467 + #define mt7996_for_each_phy(dev, phy) \ 468 + for (int __i = 0; __i < ARRAY_SIZE((dev)->radio_phy); __i++) \ 469 + if (((phy) = (dev)->radio_phy[__i]) != NULL) 464 470 465 471 extern const struct ieee80211_ops mt7996_ops; 466 472 extern struct pci_driver mt7996_pci_driver; ··· 528 424 u64 __mt7996_get_tsf(struct ieee80211_hw *hw, struct mt7996_vif *mvif); 529 425 int mt7996_register_device(struct mt7996_dev *dev); 530 426 void mt7996_unregister_device(struct mt7996_dev *dev); 427 + int mt7996_vif_link_add(struct mt76_phy *mphy, struct ieee80211_vif *vif, 428 + struct ieee80211_bss_conf *link_conf, 429 + struct mt76_vif_link *mlink); 430 + void mt7996_vif_link_remove(struct mt76_phy *mphy, struct ieee80211_vif *vif, 431 + struct ieee80211_bss_conf *link_conf, 432 + struct mt76_vif_link *mlink); 531 433 int mt7996_eeprom_init(struct mt7996_dev *dev); 532 434 int mt7996_eeprom_parse_hw_cap(struct mt7996_dev *dev, struct mt7996_phy *phy); 533 435 int mt7996_eeprom_get_target_power(struct mt7996_dev *dev, ··· 549 439 void mt7996_init_txpower(struct mt7996_phy *phy); 550 440 int mt7996_txbf_init(struct mt7996_dev *dev); 551 441 void mt7996_reset(struct mt7996_dev *dev); 552 - int mt7996_run(struct ieee80211_hw *hw); 442 + int mt7996_run(struct mt7996_phy *phy); 553 443 int mt7996_mcu_init(struct mt7996_dev *dev); 554 444 int mt7996_mcu_init_firmware(struct mt7996_dev *dev); 555 445 int mt7996_mcu_twt_agrt_update(struct mt7996_dev *dev, 556 446 struct mt7996_vif *mvif, 557 447 struct mt7996_twt_flow *flow, 558 448 int cmd); 559 - int mt7996_mcu_add_dev_info(struct mt7996_phy *phy, 560 - struct ieee80211_vif *vif, bool enable); 561 - int mt7996_mcu_add_bss_info(struct mt7996_phy *phy, 562 - struct ieee80211_vif *vif, int enable); 449 + int mt7996_mcu_add_dev_info(struct mt7996_phy *phy, struct ieee80211_vif *vif, 450 + struct ieee80211_bss_conf *link_conf, 451 + struct mt76_vif_link *mlink, bool enable); 452 + int mt7996_mcu_add_bss_info(struct mt7996_phy *phy, struct ieee80211_vif *vif, 453 + struct ieee80211_bss_conf *link_conf, 454 + struct mt76_vif_link *mlink, int enable); 563 455 int mt7996_mcu_add_sta(struct mt7996_dev *dev, struct ieee80211_vif *vif, 564 - struct ieee80211_sta *sta, bool enable, bool newly); 456 + struct mt76_vif_link *mlink, 457 + struct ieee80211_sta *sta, int conn_state, bool newly); 565 458 int mt7996_mcu_add_tx_ba(struct mt7996_dev *dev, 566 459 struct ieee80211_ampdu_params *params, 567 460 bool add); 568 461 int mt7996_mcu_add_rx_ba(struct mt7996_dev *dev, 569 462 struct ieee80211_ampdu_params *params, 570 463 bool add); 571 - int mt7996_mcu_update_bss_color(struct mt7996_dev *dev, struct ieee80211_vif *vif, 464 + int mt7996_mcu_update_bss_color(struct mt7996_dev *dev, 465 + struct mt76_vif_link *mlink, 572 466 struct cfg80211_he_bss_color *he_bss_color); 573 467 int mt7996_mcu_add_beacon(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 574 - int enable); 468 + struct ieee80211_bss_conf *link_conf); 575 469 int mt7996_mcu_beacon_inband_discov(struct mt7996_dev *dev, 576 470 struct ieee80211_vif *vif, u32 changed); 577 471 int mt7996_mcu_add_obss_spr(struct mt7996_phy *phy, struct ieee80211_vif *vif, ··· 584 470 struct ieee80211_sta *sta, bool changed); 585 471 int mt7996_set_channel(struct mt76_phy *mphy); 586 472 int mt7996_mcu_set_chan_info(struct mt7996_phy *phy, u16 tag); 587 - int mt7996_mcu_set_tx(struct mt7996_dev *dev, struct ieee80211_vif *vif); 473 + int mt7996_mcu_set_tx(struct mt7996_dev *dev, struct ieee80211_vif *vif, 474 + struct ieee80211_bss_conf *link_conf); 588 475 int mt7996_mcu_set_fixed_rate_ctrl(struct mt7996_dev *dev, 589 476 void *data, u16 version); 590 477 int mt7996_mcu_set_fixed_field(struct mt7996_dev *dev, struct ieee80211_vif *vif, 591 478 struct ieee80211_sta *sta, void *data, u32 field); 592 479 int mt7996_mcu_set_eeprom(struct mt7996_dev *dev); 593 - int mt7996_mcu_get_eeprom(struct mt7996_dev *dev, u32 offset); 480 + int mt7996_mcu_get_eeprom(struct mt7996_dev *dev, u32 offset, u8 *buf, u32 buf_len); 594 481 int mt7996_mcu_get_eeprom_free_block(struct mt7996_dev *dev, u8 *block_num); 595 482 int mt7996_mcu_get_chip_config(struct mt7996_dev *dev, u32 *cap); 596 483 int mt7996_mcu_set_ser(struct mt7996_dev *dev, u8 action, u8 set, u8 band); ··· 603 488 const struct mt7996_dfs_pattern *pattern); 604 489 int mt7996_mcu_set_radio_en(struct mt7996_phy *phy, bool enable); 605 490 int mt7996_mcu_set_rts_thresh(struct mt7996_phy *phy, u32 val); 606 - int mt7996_mcu_set_timing(struct mt7996_phy *phy, struct ieee80211_vif *vif); 491 + int mt7996_mcu_set_timing(struct mt7996_phy *phy, struct ieee80211_vif *vif, 492 + struct ieee80211_bss_conf *link_conf); 607 493 int mt7996_mcu_get_chan_mib_info(struct mt7996_phy *phy, bool chan_switch); 608 494 int mt7996_mcu_get_temperature(struct mt7996_phy *phy); 609 495 int mt7996_mcu_set_thermal_throttling(struct mt7996_phy *phy, u8 state); ··· 627 511 void mt7996_mcu_exit(struct mt7996_dev *dev); 628 512 int mt7996_mcu_get_all_sta_info(struct mt7996_phy *phy, u16 tag); 629 513 int mt7996_mcu_wed_rro_reset_sessions(struct mt7996_dev *dev, u16 id); 514 + int mt7996_mcu_set_sniffer_mode(struct mt7996_phy *phy, bool enabled); 630 515 631 516 static inline u8 mt7996_max_interface_num(struct mt7996_dev *dev) 632 517 { ··· 692 575 void mt7996_mac_set_coverage_class(struct mt7996_phy *phy); 693 576 int mt7996_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, 694 577 struct ieee80211_sta *sta); 578 + int mt7996_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif, 579 + struct ieee80211_sta *sta, enum mt76_sta_event ev); 695 580 void mt7996_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, 696 581 struct ieee80211_sta *sta); 697 582 void mt7996_mac_work(struct work_struct *work); ··· 721 602 void mt7996_set_stream_he_eht_caps(struct mt7996_phy *phy); 722 603 void mt7996_set_stream_vht_txbf_caps(struct mt7996_phy *phy); 723 604 void mt7996_update_channel(struct mt76_phy *mphy); 724 - int mt7996_init_debugfs(struct mt7996_phy *phy); 605 + int mt7996_init_debugfs(struct mt7996_dev *dev); 725 606 void mt7996_debugfs_rx_fw_monitor(struct mt7996_dev *dev, const void *data, int len); 726 607 bool mt7996_debugfs_rx_log(struct mt7996_dev *dev, const void *data, int len); 727 608 int mt7996_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif,
+12
drivers/net/wireless/mediatek/mt76/mt7996/regs.h
··· 175 175 #define MT_WTBLOFF_RSCR_RCPI_MODE GENMASK(31, 30) 176 176 #define MT_WTBLOFF_RSCR_RCPI_PARAM GENMASK(25, 24) 177 177 178 + #define MT_WTBLOFF_ACR(_band) MT_WTBLOFF(_band, 0x010) 179 + #define MT_WTBLOFF_ADM_BACKOFFTIME BIT(29) 180 + 178 181 /* ETBF: band 0(0x820ea000), band 1(0x820fa000), band 2(0x830ea000) */ 179 182 #define MT_WF_ETBF_BASE(_band) __BASE(WF_ETBF_BASE, (_band)) 180 183 #define MT_WF_ETBF(_band, ofs) (MT_WF_ETBF_BASE(_band) + (ofs)) ··· 663 660 #define MT_TOP_MISC MT_TOP(0xf0) 664 661 #define MT_TOP_MISC_FW_STATE GENMASK(2, 0) 665 662 663 + /* ADIE */ 664 + #define MT_ADIE_CHIP_ID(_idx) (0x0f00002c + ((_idx) << 28)) 665 + #define MT_ADIE_VERSION_MASK GENMASK(15, 0) 666 + #define MT_ADIE_CHIP_ID_MASK GENMASK(31, 16) 667 + 666 668 #define MT_PAD_GPIO 0x700056f0 667 669 #define MT_PAD_GPIO_ADIE_COMB GENMASK(16, 15) 670 + #define MT_PAD_GPIO_2ADIE_TBTC BIT(19) 671 + /* for mt7992 */ 672 + #define MT_PAD_GPIO_ADIE_COMB_7992 GENMASK(17, 16) 673 + #define MT_PAD_GPIO_ADIE_SINGLE BIT(15) 668 674 669 675 #define MT_HW_REV 0x70010204 670 676 #define MT_HW_REV1 0x8a00
+168
drivers/net/wireless/mediatek/mt76/scan.c
··· 1 + // SPDX-License-Identifier: ISC 2 + /* 3 + * Copyright (C) 2024 Felix Fietkau <nbd@nbd.name> 4 + */ 5 + #include "mt76.h" 6 + 7 + static void mt76_scan_complete(struct mt76_dev *dev, bool abort) 8 + { 9 + struct mt76_phy *phy = dev->scan.phy; 10 + struct cfg80211_scan_info info = { 11 + .aborted = abort, 12 + }; 13 + 14 + if (!phy) 15 + return; 16 + 17 + clear_bit(MT76_SCANNING, &phy->state); 18 + 19 + if (dev->scan.chan && phy->main_chandef.chan) 20 + mt76_set_channel(phy, &phy->main_chandef, false); 21 + mt76_put_vif_phy_link(phy, dev->scan.vif, dev->scan.mlink); 22 + memset(&dev->scan, 0, sizeof(dev->scan)); 23 + ieee80211_scan_completed(phy->hw, &info); 24 + } 25 + 26 + void mt76_abort_scan(struct mt76_dev *dev) 27 + { 28 + cancel_delayed_work_sync(&dev->scan_work); 29 + mt76_scan_complete(dev, true); 30 + } 31 + 32 + static void 33 + mt76_scan_send_probe(struct mt76_dev *dev, struct cfg80211_ssid *ssid) 34 + { 35 + struct cfg80211_scan_request *req = dev->scan.req; 36 + struct ieee80211_vif *vif = dev->scan.vif; 37 + struct mt76_vif_link *mvif = dev->scan.mlink; 38 + enum nl80211_band band = dev->scan.chan->band; 39 + struct mt76_phy *phy = dev->scan.phy; 40 + struct ieee80211_tx_info *info; 41 + struct sk_buff *skb; 42 + 43 + skb = ieee80211_probereq_get(phy->hw, vif->addr, ssid->ssid, 44 + ssid->ssid_len, req->ie_len); 45 + if (!skb) 46 + return; 47 + 48 + if (is_unicast_ether_addr(req->bssid)) { 49 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 50 + 51 + ether_addr_copy(hdr->addr1, req->bssid); 52 + ether_addr_copy(hdr->addr3, req->bssid); 53 + } 54 + 55 + info = IEEE80211_SKB_CB(skb); 56 + if (req->no_cck) 57 + info->flags |= IEEE80211_TX_CTL_NO_CCK_RATE; 58 + info->control.flags |= IEEE80211_TX_CTRL_DONT_USE_RATE_MASK; 59 + 60 + if (req->ie_len) 61 + skb_put_data(skb, req->ie, req->ie_len); 62 + 63 + skb->priority = 7; 64 + skb_set_queue_mapping(skb, IEEE80211_AC_VO); 65 + 66 + rcu_read_lock(); 67 + if (ieee80211_tx_prepare_skb(phy->hw, vif, skb, band, NULL)) 68 + mt76_tx(phy, NULL, mvif->wcid, skb); 69 + else 70 + ieee80211_free_txskb(phy->hw, skb); 71 + rcu_read_unlock(); 72 + } 73 + 74 + void mt76_scan_work(struct work_struct *work) 75 + { 76 + struct mt76_dev *dev = container_of(work, struct mt76_dev, 77 + scan_work.work); 78 + struct cfg80211_scan_request *req = dev->scan.req; 79 + struct cfg80211_chan_def chandef = {}; 80 + struct mt76_phy *phy = dev->scan.phy; 81 + int duration = HZ / 9; /* ~110 ms */ 82 + int i; 83 + 84 + if (dev->scan.chan_idx >= req->n_channels) { 85 + mt76_scan_complete(dev, false); 86 + return; 87 + } 88 + 89 + if (dev->scan.chan && phy->num_sta) { 90 + dev->scan.chan = NULL; 91 + mt76_set_channel(phy, &phy->main_chandef, false); 92 + goto out; 93 + } 94 + 95 + dev->scan.chan = req->channels[dev->scan.chan_idx++]; 96 + cfg80211_chandef_create(&chandef, dev->scan.chan, NL80211_CHAN_HT20); 97 + mt76_set_channel(phy, &chandef, true); 98 + 99 + if (!req->n_ssids || 100 + chandef.chan->flags & (IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_RADAR)) 101 + goto out; 102 + 103 + duration = HZ / 16; /* ~60 ms */ 104 + local_bh_disable(); 105 + for (i = 0; i < req->n_ssids; i++) 106 + mt76_scan_send_probe(dev, &req->ssids[i]); 107 + local_bh_enable(); 108 + 109 + out: 110 + if (!duration) 111 + return; 112 + 113 + if (dev->scan.chan) 114 + duration = max_t(int, duration, 115 + msecs_to_jiffies(req->duration + 116 + (req->duration >> 5))); 117 + 118 + ieee80211_queue_delayed_work(dev->phy.hw, &dev->scan_work, duration); 119 + } 120 + 121 + int mt76_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 122 + struct ieee80211_scan_request *req) 123 + { 124 + struct mt76_phy *phy = hw->priv; 125 + struct mt76_dev *dev = phy->dev; 126 + struct mt76_vif_link *mlink; 127 + int ret = 0; 128 + 129 + if (hw->wiphy->n_radio > 1) { 130 + phy = dev->band_phys[req->req.channels[0]->band]; 131 + if (!phy) 132 + return -EINVAL; 133 + } 134 + 135 + mutex_lock(&dev->mutex); 136 + 137 + if (dev->scan.req || phy->roc_vif) { 138 + ret = -EBUSY; 139 + goto out; 140 + } 141 + 142 + mlink = mt76_get_vif_phy_link(phy, vif); 143 + if (IS_ERR(mlink)) { 144 + ret = PTR_ERR(mlink); 145 + goto out; 146 + } 147 + 148 + memset(&dev->scan, 0, sizeof(dev->scan)); 149 + dev->scan.req = &req->req; 150 + dev->scan.vif = vif; 151 + dev->scan.phy = phy; 152 + dev->scan.mlink = mlink; 153 + ieee80211_queue_delayed_work(dev->phy.hw, &dev->scan_work, 0); 154 + 155 + out: 156 + mutex_unlock(&dev->mutex); 157 + 158 + return ret; 159 + } 160 + EXPORT_SYMBOL_GPL(mt76_hw_scan); 161 + 162 + void mt76_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 163 + { 164 + struct mt76_phy *phy = hw->priv; 165 + 166 + mt76_abort_scan(phy->dev); 167 + } 168 + EXPORT_SYMBOL_GPL(mt76_cancel_hw_scan);
+4
drivers/net/wireless/mediatek/mt76/sdio_txrx.c
··· 46 46 return 0; 47 47 48 48 sdio->sched.pse_mcu_quota += pse_mcu_quota; 49 + if (sdio->pse_mcu_quota_max && 50 + sdio->sched.pse_mcu_quota > sdio->pse_mcu_quota_max) { 51 + sdio->sched.pse_mcu_quota = sdio->pse_mcu_quota_max; 52 + } 49 53 sdio->sched.pse_data_quota += pse_data_quota; 50 54 sdio->sched.ple_data_quota += ple_data_quota; 51 55
+19 -14
drivers/net/wireless/mediatek/mt76/tx.c
··· 489 489 490 490 do { 491 491 if (test_bit(MT76_RESET, &phy->state) || phy->offchannel) 492 - return -EBUSY; 492 + break; 493 493 494 494 if (stop || mt76_txq_stopped(q)) 495 495 break; ··· 522 522 static int 523 523 mt76_txq_schedule_list(struct mt76_phy *phy, enum mt76_txq_id qid) 524 524 { 525 - struct mt76_queue *q = phy->q_tx[qid]; 526 525 struct mt76_dev *dev = phy->dev; 527 526 struct ieee80211_txq *txq; 528 527 struct mt76_txq *mtxq; 529 528 struct mt76_wcid *wcid; 529 + struct mt76_queue *q; 530 530 int ret = 0; 531 531 532 532 while (1) { 533 533 int n_frames = 0; 534 - 535 - if (test_bit(MT76_RESET, &phy->state) || phy->offchannel) 536 - return -EBUSY; 537 - 538 - if (dev->queue_ops->tx_cleanup && 539 - q->queued + 2 * MT_TXQ_FREE_THR >= q->ndesc) { 540 - dev->queue_ops->tx_cleanup(dev, q, false); 541 - } 542 534 543 535 txq = ieee80211_next_txq(phy->hw, qid); 544 536 if (!txq) ··· 540 548 wcid = rcu_dereference(dev->wcid[mtxq->wcid]); 541 549 if (!wcid || test_bit(MT_WCID_FLAG_PS, &wcid->flags)) 542 550 continue; 551 + 552 + phy = mt76_dev_phy(dev, wcid->phy_idx); 553 + if (test_bit(MT76_RESET, &phy->state) || phy->offchannel) 554 + continue; 555 + 556 + q = phy->q_tx[qid]; 557 + if (dev->queue_ops->tx_cleanup && 558 + q->queued + 2 * MT_TXQ_FREE_THR >= q->ndesc) { 559 + dev->queue_ops->tx_cleanup(dev, q, false); 560 + } 543 561 544 562 if (mtxq->send_bar && mtxq->aggr) { 545 563 struct ieee80211_txq *txq = mtxq_to_txq(mtxq); ··· 580 578 { 581 579 int len; 582 580 583 - if (qid >= 4 || phy->offchannel) 581 + if (qid >= 4) 584 582 return; 585 583 586 584 local_bh_disable(); ··· 682 680 683 681 void mt76_txq_schedule_all(struct mt76_phy *phy) 684 682 { 683 + struct mt76_phy *main_phy = &phy->dev->phy; 685 684 int i; 686 685 687 686 mt76_txq_schedule_pending(phy); 687 + 688 + if (phy != main_phy && phy->hw == main_phy->hw) 689 + return; 690 + 688 691 for (i = 0; i <= MT_TXQ_BK; i++) 689 692 mt76_txq_schedule(phy, i); 690 693 } ··· 700 693 struct mt76_phy *phy; 701 694 int i; 702 695 696 + mt76_txq_schedule_all(&dev->phy); 703 697 for (i = 0; i < ARRAY_SIZE(dev->phys); i++) { 704 698 phy = dev->phys[i]; 705 699 if (!phy) ··· 755 747 { 756 748 struct mt76_phy *phy = hw->priv; 757 749 struct mt76_dev *dev = phy->dev; 758 - 759 - if (!test_bit(MT76_STATE_RUNNING, &phy->state)) 760 - return; 761 750 762 751 mt76_worker_schedule(&dev->tx_worker); 763 752 }
+2 -2
drivers/net/wireless/mediatek/mt76/usb.c
··· 33 33 34 34 ret = usb_control_msg(udev, pipe, req, req_type, val, 35 35 offset, buf, len, MT_VEND_REQ_TOUT_MS); 36 - if (ret == -ENODEV) 36 + if (ret == -ENODEV || ret == -EPROTO) 37 37 set_bit(MT76_REMOVED, &dev->phy.state); 38 - if (ret >= 0 || ret == -ENODEV) 38 + if (ret >= 0 || ret == -ENODEV || ret == -EPROTO) 39 39 return ret; 40 40 usleep_range(5000, 10000); 41 41 }
+3 -7
drivers/net/wireless/mediatek/mt76/util.c
··· 64 64 } 65 65 EXPORT_SYMBOL_GPL(mt76_wcid_alloc); 66 66 67 - int mt76_get_min_avg_rssi(struct mt76_dev *dev, bool ext_phy) 67 + int mt76_get_min_avg_rssi(struct mt76_dev *dev, u8 phy_idx) 68 68 { 69 69 struct mt76_wcid *wcid; 70 70 int i, j, min_rssi = 0; ··· 75 75 76 76 for (i = 0; i < ARRAY_SIZE(dev->wcid_mask); i++) { 77 77 u32 mask = dev->wcid_mask[i]; 78 - u32 phy_mask = dev->wcid_phy_mask[i]; 79 78 80 79 if (!mask) 81 80 continue; 82 81 83 - for (j = i * 32; mask; j++, mask >>= 1, phy_mask >>= 1) { 82 + for (j = i * 32; mask; j++, mask >>= 1) { 84 83 if (!(mask & 1)) 85 84 continue; 86 85 87 - if (!!(phy_mask & 1) != ext_phy) 88 - continue; 89 - 90 86 wcid = rcu_dereference(dev->wcid[j]); 91 - if (!wcid) 87 + if (!wcid || wcid->phy_idx != phy_idx) 92 88 continue; 93 89 94 90 spin_lock(&dev->rx_lock);