1 // SPDX-License-Identifier: ISC 2 /* Copyright (C) 2019 MediaTek Inc. 3 * 4 * Author: Roy Luo <royluo@google.com> 5 * Ryder Lee <ryder.lee@mediatek.com> 6 * Felix Fietkau <nbd@nbd.name> 7 * Lorenzo Bianconi <lorenzo@kernel.org> 8 */ 9 10 #include <linux/etherdevice.h> 11 #include <linux/module.h> 12 #include "mt7615.h" 13 #include "mcu.h" 14 15 static bool mt7615_dev_running(struct mt7615_dev *dev) 16 { 17 struct mt7615_phy *phy; 18 19 if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) 20 return true; 21 22 phy = mt7615_ext_phy(dev); 23 24 return phy && test_bit(MT76_STATE_RUNNING, &phy->mt76->state); 25 } 26 27 static int mt7615_start(struct ieee80211_hw *hw) 28 { 29 struct mt7615_dev *dev = mt7615_hw_dev(hw); 30 struct mt7615_phy *phy = mt7615_hw_phy(hw); 31 unsigned long timeout; 32 bool running; 33 int ret; 34 35 if (!mt7615_wait_for_mcu_init(dev)) 36 return -EIO; 37 38 mt7615_mutex_acquire(dev); 39 40 running = mt7615_dev_running(dev); 41 42 if (!running) { 43 ret = mt7615_mcu_set_pm(dev, 0, 0); 44 if (ret) 45 goto out; 46 47 ret = mt76_connac_mcu_set_mac_enable(&dev->mt76, 0, true, false); 48 if (ret) 49 goto out; 50 51 mt7615_mac_enable_nf(dev, 0); 52 } 53 54 if (phy != &dev->phy) { 55 ret = mt7615_mcu_set_pm(dev, 1, 0); 56 if (ret) 57 goto out; 58 59 ret = mt76_connac_mcu_set_mac_enable(&dev->mt76, 1, true, false); 60 if (ret) 61 goto out; 62 63 mt7615_mac_enable_nf(dev, 1); 64 } 65 66 if (mt7615_firmware_offload(dev)) { 67 ret = mt76_connac_mcu_set_channel_domain(phy->mt76); 68 if (ret) 69 goto out; 70 71 ret = mt76_connac_mcu_set_rate_txpower(phy->mt76); 72 if (ret) 73 goto out; 74 } 75 76 ret = mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD_SET_RX_PATH); 77 if (ret) 78 goto out; 79 80 set_bit(MT76_STATE_RUNNING, &phy->mt76->state); 81 82 timeout = mt7615_get_macwork_timeout(dev); 83 ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work, timeout); 84 85 if (!running) 86 mt7615_mac_reset_counters(dev); 87 88 out: 89 mt7615_mutex_release(dev); 90 91 return ret; 92 } 93 94 static void mt7615_stop(struct ieee80211_hw *hw) 95 { 96 struct mt7615_dev *dev = mt7615_hw_dev(hw); 97 struct mt7615_phy *phy = mt7615_hw_phy(hw); 98 99 cancel_delayed_work_sync(&phy->mt76->mac_work); 100 del_timer_sync(&phy->roc_timer); 101 cancel_work_sync(&phy->roc_work); 102 103 cancel_delayed_work_sync(&dev->pm.ps_work); 104 cancel_work_sync(&dev->pm.wake_work); 105 106 mt76_connac_free_pending_tx_skbs(&dev->pm, NULL); 107 108 mt7615_mutex_acquire(dev); 109 110 mt76_testmode_reset(phy->mt76, true); 111 112 clear_bit(MT76_STATE_RUNNING, &phy->mt76->state); 113 cancel_delayed_work_sync(&phy->scan_work); 114 115 if (phy != &dev->phy) { 116 mt7615_mcu_set_pm(dev, 1, 1); 117 mt76_connac_mcu_set_mac_enable(&dev->mt76, 1, false, false); 118 } 119 120 if (!mt7615_dev_running(dev)) { 121 mt7615_mcu_set_pm(dev, 0, 1); 122 mt76_connac_mcu_set_mac_enable(&dev->mt76, 0, false, false); 123 } 124 125 mt7615_mutex_release(dev); 126 } 127 128 static inline int get_free_idx(u32 mask, u8 start, u8 end) 129 { 130 return ffs(~mask & GENMASK(end, start)); 131 } 132 133 static int get_omac_idx(enum nl80211_iftype type, u64 mask) 134 { 135 int i; 136 137 switch (type) { 138 case NL80211_IFTYPE_STATION: 139 /* prefer hw bssid slot 1-3 */ 140 i = get_free_idx(mask, HW_BSSID_1, HW_BSSID_3); 141 if (i) 142 return i - 1; 143 144 if (type != NL80211_IFTYPE_STATION) 145 break; 146 147 /* next, try to find a free repeater entry for the sta */ 148 i = get_free_idx(mask >> REPEATER_BSSID_START, 0, 149 REPEATER_BSSID_MAX - REPEATER_BSSID_START); 150 if (i) 151 return i + 32 - 1; 152 153 i = get_free_idx(mask, EXT_BSSID_1, EXT_BSSID_MAX); 154 if (i) 155 return i - 1; 156 157 if (~mask & BIT(HW_BSSID_0)) 158 return HW_BSSID_0; 159 160 break; 161 case NL80211_IFTYPE_ADHOC: 162 case NL80211_IFTYPE_MESH_POINT: 163 case NL80211_IFTYPE_MONITOR: 164 case NL80211_IFTYPE_AP: 165 /* ap uses hw bssid 0 and ext bssid */ 166 if (~mask & BIT(HW_BSSID_0)) 167 return HW_BSSID_0; 168 169 i = get_free_idx(mask, EXT_BSSID_1, EXT_BSSID_MAX); 170 if (i) 171 return i - 1; 172 173 break; 174 default: 175 WARN_ON(1); 176 break; 177 } 178 179 return -1; 180 } 181 182 static int mt7615_add_interface(struct ieee80211_hw *hw, 183 struct ieee80211_vif *vif) 184 { 185 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv; 186 struct mt7615_dev *dev = mt7615_hw_dev(hw); 187 struct mt7615_phy *phy = mt7615_hw_phy(hw); 188 struct mt76_txq *mtxq; 189 bool ext_phy = phy != &dev->phy; 190 int idx, ret = 0; 191 192 mt7615_mutex_acquire(dev); 193 194 mt76_testmode_reset(phy->mt76, true); 195 196 if (vif->type == NL80211_IFTYPE_MONITOR && 197 is_zero_ether_addr(vif->addr)) 198 phy->monitor_vif = vif; 199 200 mvif->mt76.idx = ffs(~dev->mt76.vif_mask) - 1; 201 if (mvif->mt76.idx >= MT7615_MAX_INTERFACES) { 202 ret = -ENOSPC; 203 goto out; 204 } 205 206 idx = get_omac_idx(vif->type, dev->omac_mask); 207 if (idx < 0) { 208 ret = -ENOSPC; 209 goto out; 210 } 211 mvif->mt76.omac_idx = idx; 212 213 mvif->mt76.band_idx = ext_phy; 214 if (mt7615_ext_phy(dev)) 215 mvif->mt76.wmm_idx = ext_phy * (MT7615_MAX_WMM_SETS / 2) + 216 mvif->mt76.idx % (MT7615_MAX_WMM_SETS / 2); 217 else 218 mvif->mt76.wmm_idx = mvif->mt76.idx % MT7615_MAX_WMM_SETS; 219 220 dev->mt76.vif_mask |= BIT(mvif->mt76.idx); 221 dev->omac_mask |= BIT_ULL(mvif->mt76.omac_idx); 222 phy->omac_mask |= BIT_ULL(mvif->mt76.omac_idx); 223 224 ret = mt7615_mcu_set_dbdc(dev); 225 if (ret) 226 goto out; 227 228 idx = MT7615_WTBL_RESERVED - mvif->mt76.idx; 229 230 INIT_LIST_HEAD(&mvif->sta.poll_list); 231 mvif->sta.wcid.idx = idx; 232 mvif->sta.wcid.ext_phy = mvif->mt76.band_idx; 233 mvif->sta.wcid.hw_key_idx = -1; 234 mt76_packet_id_init(&mvif->sta.wcid); 235 236 mt7615_mac_wtbl_update(dev, idx, 237 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); 238 239 rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid); 240 if (vif->txq) { 241 mtxq = (struct mt76_txq *)vif->txq->drv_priv; 242 mtxq->wcid = &mvif->sta.wcid; 243 } 244 245 ret = mt7615_mcu_add_dev_info(phy, vif, true); 246 out: 247 mt7615_mutex_release(dev); 248 249 return ret; 250 } 251 252 static void mt7615_remove_interface(struct ieee80211_hw *hw, 253 struct ieee80211_vif *vif) 254 { 255 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv; 256 struct mt7615_sta *msta = &mvif->sta; 257 struct mt7615_dev *dev = mt7615_hw_dev(hw); 258 struct mt7615_phy *phy = mt7615_hw_phy(hw); 259 int idx = msta->wcid.idx; 260 261 mt7615_mutex_acquire(dev); 262 263 mt7615_mcu_add_bss_info(phy, vif, NULL, false); 264 mt7615_mcu_sta_add(phy, vif, NULL, false); 265 266 mt76_testmode_reset(phy->mt76, true); 267 if (vif == phy->monitor_vif) 268 phy->monitor_vif = NULL; 269 270 mt76_connac_free_pending_tx_skbs(&dev->pm, &msta->wcid); 271 272 mt7615_mcu_add_dev_info(phy, vif, false); 273 274 rcu_assign_pointer(dev->mt76.wcid[idx], NULL); 275 276 dev->mt76.vif_mask &= ~BIT(mvif->mt76.idx); 277 dev->omac_mask &= ~BIT_ULL(mvif->mt76.omac_idx); 278 phy->omac_mask &= ~BIT_ULL(mvif->mt76.omac_idx); 279 280 mt7615_mutex_release(dev); 281 282 spin_lock_bh(&dev->sta_poll_lock); 283 if (!list_empty(&msta->poll_list)) 284 list_del_init(&msta->poll_list); 285 spin_unlock_bh(&dev->sta_poll_lock); 286 287 mt76_packet_id_flush(&dev->mt76, &mvif->sta.wcid); 288 } 289 290 static void mt7615_init_dfs_state(struct mt7615_phy *phy) 291 { 292 struct mt76_phy *mphy = phy->mt76; 293 struct ieee80211_hw *hw = mphy->hw; 294 struct cfg80211_chan_def *chandef = &hw->conf.chandef; 295 296 if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) 297 return; 298 299 if (!(chandef->chan->flags & IEEE80211_CHAN_RADAR)) 300 return; 301 302 if (mphy->chandef.chan->center_freq == chandef->chan->center_freq && 303 mphy->chandef.width == chandef->width) 304 return; 305 306 phy->dfs_state = -1; 307 } 308 309 int mt7615_set_channel(struct mt7615_phy *phy) 310 { 311 struct mt7615_dev *dev = phy->dev; 312 bool ext_phy = phy != &dev->phy; 313 int ret; 314 315 cancel_delayed_work_sync(&phy->mt76->mac_work); 316 317 mt7615_mutex_acquire(dev); 318 319 set_bit(MT76_RESET, &phy->mt76->state); 320 321 mt7615_init_dfs_state(phy); 322 mt76_set_channel(phy->mt76); 323 324 if (is_mt7615(&dev->mt76) && dev->flash_eeprom) { 325 ret = mt7615_mcu_apply_rx_dcoc(phy); 326 if (ret) 327 goto out; 328 329 ret = mt7615_mcu_apply_tx_dpd(phy); 330 if (ret) 331 goto out; 332 } 333 334 ret = mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD_CHANNEL_SWITCH); 335 if (ret) 336 goto out; 337 338 mt7615_mac_set_timing(phy); 339 ret = mt7615_dfs_init_radar_detector(phy); 340 if (ret) 341 goto out; 342 343 mt7615_mac_cca_stats_reset(phy); 344 ret = mt7615_mcu_set_sku_en(phy, true); 345 if (ret) 346 goto out; 347 348 mt7615_mac_reset_counters(dev); 349 phy->noise = 0; 350 phy->chfreq = mt76_rr(dev, MT_CHFREQ(ext_phy)); 351 352 out: 353 clear_bit(MT76_RESET, &phy->mt76->state); 354 355 mt7615_mutex_release(dev); 356 357 mt76_worker_schedule(&dev->mt76.tx_worker); 358 if (!mt76_testmode_enabled(phy->mt76)) { 359 unsigned long timeout = mt7615_get_macwork_timeout(dev); 360 361 ieee80211_queue_delayed_work(phy->mt76->hw, 362 &phy->mt76->mac_work, timeout); 363 } 364 365 return ret; 366 } 367 368 static int mt7615_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 369 struct ieee80211_vif *vif, struct ieee80211_sta *sta, 370 struct ieee80211_key_conf *key) 371 { 372 struct mt7615_dev *dev = mt7615_hw_dev(hw); 373 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv; 374 struct mt7615_sta *msta = sta ? (struct mt7615_sta *)sta->drv_priv : 375 &mvif->sta; 376 struct mt76_wcid *wcid = &msta->wcid; 377 int idx = key->keyidx, err = 0; 378 u8 *wcid_keyidx = &wcid->hw_key_idx; 379 380 /* The hardware does not support per-STA RX GTK, fallback 381 * to software mode for these. 382 */ 383 if ((vif->type == NL80211_IFTYPE_ADHOC || 384 vif->type == NL80211_IFTYPE_MESH_POINT) && 385 (key->cipher == WLAN_CIPHER_SUITE_TKIP || 386 key->cipher == WLAN_CIPHER_SUITE_CCMP) && 387 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) 388 return -EOPNOTSUPP; 389 390 /* fall back to sw encryption for unsupported ciphers */ 391 switch (key->cipher) { 392 case WLAN_CIPHER_SUITE_AES_CMAC: 393 wcid_keyidx = &wcid->hw_key_idx2; 394 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE; 395 break; 396 case WLAN_CIPHER_SUITE_TKIP: 397 case WLAN_CIPHER_SUITE_CCMP: 398 case WLAN_CIPHER_SUITE_CCMP_256: 399 case WLAN_CIPHER_SUITE_GCMP: 400 case WLAN_CIPHER_SUITE_GCMP_256: 401 case WLAN_CIPHER_SUITE_SMS4: 402 break; 403 case WLAN_CIPHER_SUITE_WEP40: 404 case WLAN_CIPHER_SUITE_WEP104: 405 default: 406 return -EOPNOTSUPP; 407 } 408 409 mt7615_mutex_acquire(dev); 410 411 if (cmd == SET_KEY) 412 *wcid_keyidx = idx; 413 else if (idx == *wcid_keyidx) 414 *wcid_keyidx = -1; 415 else 416 goto out; 417 418 mt76_wcid_key_setup(&dev->mt76, wcid, 419 cmd == SET_KEY ? key : NULL); 420 421 if (mt76_is_mmio(&dev->mt76)) 422 err = mt7615_mac_wtbl_set_key(dev, wcid, key, cmd); 423 else 424 err = __mt7615_mac_wtbl_set_key(dev, wcid, key, cmd); 425 426 out: 427 mt7615_mutex_release(dev); 428 429 return err; 430 } 431 432 static int mt7615_config(struct ieee80211_hw *hw, u32 changed) 433 { 434 struct mt7615_dev *dev = mt7615_hw_dev(hw); 435 struct mt7615_phy *phy = mt7615_hw_phy(hw); 436 bool band = phy != &dev->phy; 437 int ret = 0; 438 439 if (changed & (IEEE80211_CONF_CHANGE_CHANNEL | 440 IEEE80211_CONF_CHANGE_POWER)) { 441 #ifdef CONFIG_NL80211_TESTMODE 442 if (phy->mt76->test.state != MT76_TM_STATE_OFF) { 443 mt7615_mutex_acquire(dev); 444 mt76_testmode_reset(phy->mt76, false); 445 mt7615_mutex_release(dev); 446 } 447 #endif 448 ieee80211_stop_queues(hw); 449 ret = mt7615_set_channel(phy); 450 ieee80211_wake_queues(hw); 451 } 452 453 mt7615_mutex_acquire(dev); 454 455 if (changed & IEEE80211_CONF_CHANGE_MONITOR) { 456 mt76_testmode_reset(phy->mt76, true); 457 458 if (!(hw->conf.flags & IEEE80211_CONF_MONITOR)) 459 phy->rxfilter |= MT_WF_RFCR_DROP_OTHER_UC; 460 else 461 phy->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_UC; 462 463 mt76_wr(dev, MT_WF_RFCR(band), phy->rxfilter); 464 } 465 466 mt7615_mutex_release(dev); 467 468 return ret; 469 } 470 471 static int 472 mt7615_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue, 473 const struct ieee80211_tx_queue_params *params) 474 { 475 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; 476 struct mt7615_dev *dev = mt7615_hw_dev(hw); 477 int err; 478 479 mt7615_mutex_acquire(dev); 480 481 queue = mt7615_lmac_mapping(dev, queue); 482 queue += mvif->wmm_idx * MT7615_MAX_WMM_SETS; 483 err = mt7615_mcu_set_wmm(dev, queue, params); 484 485 mt7615_mutex_release(dev); 486 487 return err; 488 } 489 490 static void mt7615_configure_filter(struct ieee80211_hw *hw, 491 unsigned int changed_flags, 492 unsigned int *total_flags, 493 u64 multicast) 494 { 495 struct mt7615_dev *dev = mt7615_hw_dev(hw); 496 struct mt7615_phy *phy = mt7615_hw_phy(hw); 497 bool band = phy != &dev->phy; 498 499 u32 ctl_flags = MT_WF_RFCR1_DROP_ACK | 500 MT_WF_RFCR1_DROP_BF_POLL | 501 MT_WF_RFCR1_DROP_BA | 502 MT_WF_RFCR1_DROP_CFEND | 503 MT_WF_RFCR1_DROP_CFACK; 504 u32 flags = 0; 505 506 mt7615_mutex_acquire(dev); 507 508 #define MT76_FILTER(_flag, _hw) do { \ 509 flags |= *total_flags & FIF_##_flag; \ 510 phy->rxfilter &= ~(_hw); \ 511 if (!mt76_testmode_enabled(phy->mt76)) \ 512 phy->rxfilter |= !(flags & FIF_##_flag) * (_hw);\ 513 } while (0) 514 515 phy->rxfilter &= ~(MT_WF_RFCR_DROP_OTHER_BSS | 516 MT_WF_RFCR_DROP_FRAME_REPORT | 517 MT_WF_RFCR_DROP_PROBEREQ | 518 MT_WF_RFCR_DROP_MCAST_FILTERED | 519 MT_WF_RFCR_DROP_MCAST | 520 MT_WF_RFCR_DROP_BCAST | 521 MT_WF_RFCR_DROP_DUPLICATE | 522 MT_WF_RFCR_DROP_A2_BSSID | 523 MT_WF_RFCR_DROP_UNWANTED_CTL | 524 MT_WF_RFCR_DROP_STBC_MULTI); 525 526 if (phy->n_beacon_vif || !mt7615_firmware_offload(dev)) 527 phy->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_BEACON; 528 529 MT76_FILTER(OTHER_BSS, MT_WF_RFCR_DROP_OTHER_TIM | 530 MT_WF_RFCR_DROP_A3_MAC | 531 MT_WF_RFCR_DROP_A3_BSSID); 532 533 MT76_FILTER(FCSFAIL, MT_WF_RFCR_DROP_FCSFAIL); 534 535 MT76_FILTER(CONTROL, MT_WF_RFCR_DROP_CTS | 536 MT_WF_RFCR_DROP_RTS | 537 MT_WF_RFCR_DROP_CTL_RSV | 538 MT_WF_RFCR_DROP_NDPA); 539 540 *total_flags = flags; 541 mt76_wr(dev, MT_WF_RFCR(band), phy->rxfilter); 542 543 if (*total_flags & FIF_CONTROL) 544 mt76_clear(dev, MT_WF_RFCR1(band), ctl_flags); 545 else 546 mt76_set(dev, MT_WF_RFCR1(band), ctl_flags); 547 548 mt7615_mutex_release(dev); 549 } 550 551 static void mt7615_bss_info_changed(struct ieee80211_hw *hw, 552 struct ieee80211_vif *vif, 553 struct ieee80211_bss_conf *info, 554 u32 changed) 555 { 556 struct mt7615_dev *dev = mt7615_hw_dev(hw); 557 struct mt7615_phy *phy = mt7615_hw_phy(hw); 558 559 mt7615_mutex_acquire(dev); 560 561 if (changed & BSS_CHANGED_ERP_SLOT) { 562 int slottime = info->use_short_slot ? 9 : 20; 563 564 if (slottime != phy->slottime) { 565 phy->slottime = slottime; 566 mt7615_mac_set_timing(phy); 567 } 568 } 569 570 if (changed & BSS_CHANGED_BEACON_ENABLED && info->enable_beacon) { 571 mt7615_mcu_add_bss_info(phy, vif, NULL, true); 572 mt7615_mcu_sta_add(phy, vif, NULL, true); 573 574 if (mt7615_firmware_offload(dev) && vif->p2p) 575 mt76_connac_mcu_set_p2p_oppps(hw, vif); 576 } 577 578 if (changed & (BSS_CHANGED_BEACON | 579 BSS_CHANGED_BEACON_ENABLED)) 580 mt7615_mcu_add_beacon(dev, hw, vif, info->enable_beacon); 581 582 if (changed & BSS_CHANGED_PS) 583 mt76_connac_mcu_set_vif_ps(&dev->mt76, vif); 584 585 if ((changed & BSS_CHANGED_ARP_FILTER) && 586 mt7615_firmware_offload(dev)) { 587 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv; 588 589 mt76_connac_mcu_update_arp_filter(&dev->mt76, &mvif->mt76, 590 info); 591 } 592 593 if (changed & BSS_CHANGED_ASSOC) 594 mt7615_mac_set_beacon_filter(phy, vif, info->assoc); 595 596 mt7615_mutex_release(dev); 597 } 598 599 static void 600 mt7615_channel_switch_beacon(struct ieee80211_hw *hw, 601 struct ieee80211_vif *vif, 602 struct cfg80211_chan_def *chandef) 603 { 604 struct mt7615_dev *dev = mt7615_hw_dev(hw); 605 606 mt7615_mutex_acquire(dev); 607 mt7615_mcu_add_beacon(dev, hw, vif, true); 608 mt7615_mutex_release(dev); 609 } 610 611 int mt7615_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, 612 struct ieee80211_sta *sta) 613 { 614 struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76); 615 struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv; 616 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv; 617 struct mt7615_phy *phy; 618 int idx, err; 619 620 idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7615_WTBL_STA - 1); 621 if (idx < 0) 622 return -ENOSPC; 623 624 INIT_LIST_HEAD(&msta->poll_list); 625 msta->vif = mvif; 626 msta->wcid.sta = 1; 627 msta->wcid.idx = idx; 628 msta->wcid.ext_phy = mvif->mt76.band_idx; 629 630 phy = mvif->mt76.band_idx ? mt7615_ext_phy(dev) : &dev->phy; 631 err = mt76_connac_pm_wake(phy->mt76, &dev->pm); 632 if (err) 633 return err; 634 635 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) { 636 err = mt7615_mcu_add_bss_info(phy, vif, sta, true); 637 if (err) 638 return err; 639 } 640 641 mt7615_mac_wtbl_update(dev, idx, 642 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); 643 err = mt7615_mcu_sta_add(&dev->phy, vif, sta, true); 644 if (err) 645 return err; 646 647 mt76_connac_power_save_sched(phy->mt76, &dev->pm); 648 649 return err; 650 } 651 EXPORT_SYMBOL_GPL(mt7615_mac_sta_add); 652 653 void mt7615_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, 654 struct ieee80211_sta *sta) 655 { 656 struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76); 657 struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv; 658 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv; 659 struct mt7615_phy *phy; 660 661 mt76_connac_free_pending_tx_skbs(&dev->pm, &msta->wcid); 662 663 phy = mvif->mt76.band_idx ? mt7615_ext_phy(dev) : &dev->phy; 664 mt76_connac_pm_wake(phy->mt76, &dev->pm); 665 666 mt7615_mcu_sta_add(&dev->phy, vif, sta, false); 667 mt7615_mac_wtbl_update(dev, msta->wcid.idx, 668 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); 669 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) 670 mt7615_mcu_add_bss_info(phy, vif, sta, false); 671 672 spin_lock_bh(&dev->sta_poll_lock); 673 if (!list_empty(&msta->poll_list)) 674 list_del_init(&msta->poll_list); 675 spin_unlock_bh(&dev->sta_poll_lock); 676 677 mt76_connac_power_save_sched(phy->mt76, &dev->pm); 678 } 679 EXPORT_SYMBOL_GPL(mt7615_mac_sta_remove); 680 681 static void mt7615_sta_rate_tbl_update(struct ieee80211_hw *hw, 682 struct ieee80211_vif *vif, 683 struct ieee80211_sta *sta) 684 { 685 struct mt7615_dev *dev = mt7615_hw_dev(hw); 686 struct mt7615_phy *phy = mt7615_hw_phy(hw); 687 struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv; 688 struct ieee80211_sta_rates *sta_rates = rcu_dereference(sta->rates); 689 int i; 690 691 spin_lock_bh(&dev->mt76.lock); 692 for (i = 0; i < ARRAY_SIZE(msta->rates); i++) { 693 msta->rates[i].idx = sta_rates->rate[i].idx; 694 msta->rates[i].count = sta_rates->rate[i].count; 695 msta->rates[i].flags = sta_rates->rate[i].flags; 696 697 if (msta->rates[i].idx < 0 || !msta->rates[i].count) 698 break; 699 } 700 msta->n_rates = i; 701 if (mt76_connac_pm_ref(phy->mt76, &dev->pm)) { 702 mt7615_mac_set_rates(phy, msta, NULL, msta->rates); 703 mt76_connac_pm_unref(phy->mt76, &dev->pm); 704 } 705 spin_unlock_bh(&dev->mt76.lock); 706 } 707 708 void mt7615_tx_worker(struct mt76_worker *w) 709 { 710 struct mt7615_dev *dev = container_of(w, struct mt7615_dev, 711 mt76.tx_worker); 712 713 if (!mt76_connac_pm_ref(&dev->mphy, &dev->pm)) { 714 queue_work(dev->mt76.wq, &dev->pm.wake_work); 715 return; 716 } 717 718 mt76_tx_worker_run(&dev->mt76); 719 mt76_connac_pm_unref(&dev->mphy, &dev->pm); 720 } 721 722 static void mt7615_tx(struct ieee80211_hw *hw, 723 struct ieee80211_tx_control *control, 724 struct sk_buff *skb) 725 { 726 struct mt7615_dev *dev = mt7615_hw_dev(hw); 727 struct mt76_phy *mphy = hw->priv; 728 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 729 struct ieee80211_vif *vif = info->control.vif; 730 struct mt76_wcid *wcid = &dev->mt76.global_wcid; 731 struct mt7615_sta *msta = NULL; 732 int qid; 733 734 if (control->sta) { 735 msta = (struct mt7615_sta *)control->sta->drv_priv; 736 wcid = &msta->wcid; 737 } 738 739 if (vif && !control->sta) { 740 struct mt7615_vif *mvif; 741 742 mvif = (struct mt7615_vif *)vif->drv_priv; 743 msta = &mvif->sta; 744 wcid = &msta->wcid; 745 } 746 747 if (mt76_connac_pm_ref(mphy, &dev->pm)) { 748 mt76_tx(mphy, control->sta, wcid, skb); 749 mt76_connac_pm_unref(mphy, &dev->pm); 750 return; 751 } 752 753 qid = skb_get_queue_mapping(skb); 754 if (qid >= MT_TXQ_PSD) { 755 qid = IEEE80211_AC_BE; 756 skb_set_queue_mapping(skb, qid); 757 } 758 759 mt76_connac_pm_queue_skb(hw, &dev->pm, wcid, skb); 760 } 761 762 static int mt7615_set_rts_threshold(struct ieee80211_hw *hw, u32 val) 763 { 764 struct mt7615_dev *dev = mt7615_hw_dev(hw); 765 struct mt7615_phy *phy = mt7615_hw_phy(hw); 766 int err, band = phy != &dev->phy; 767 768 mt7615_mutex_acquire(dev); 769 err = mt76_connac_mcu_set_rts_thresh(&dev->mt76, val, band); 770 mt7615_mutex_release(dev); 771 772 return err; 773 } 774 775 static int 776 mt7615_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 777 struct ieee80211_ampdu_params *params) 778 { 779 enum ieee80211_ampdu_mlme_action action = params->action; 780 struct mt7615_dev *dev = mt7615_hw_dev(hw); 781 struct ieee80211_sta *sta = params->sta; 782 struct ieee80211_txq *txq = sta->txq[params->tid]; 783 struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv; 784 u16 tid = params->tid; 785 u16 ssn = params->ssn; 786 struct mt76_txq *mtxq; 787 int ret = 0; 788 789 if (!txq) 790 return -EINVAL; 791 792 mtxq = (struct mt76_txq *)txq->drv_priv; 793 794 mt7615_mutex_acquire(dev); 795 796 switch (action) { 797 case IEEE80211_AMPDU_RX_START: 798 mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, ssn, 799 params->buf_size); 800 ret = mt7615_mcu_add_rx_ba(dev, params, true); 801 break; 802 case IEEE80211_AMPDU_RX_STOP: 803 mt76_rx_aggr_stop(&dev->mt76, &msta->wcid, tid); 804 ret = mt7615_mcu_add_rx_ba(dev, params, false); 805 break; 806 case IEEE80211_AMPDU_TX_OPERATIONAL: 807 mtxq->aggr = true; 808 mtxq->send_bar = false; 809 ret = mt7615_mcu_add_tx_ba(dev, params, true); 810 ssn = mt7615_mac_get_sta_tid_sn(dev, msta->wcid.idx, tid); 811 ieee80211_send_bar(vif, sta->addr, tid, 812 IEEE80211_SN_TO_SEQ(ssn)); 813 break; 814 case IEEE80211_AMPDU_TX_STOP_FLUSH: 815 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 816 mtxq->aggr = false; 817 ret = mt7615_mcu_add_tx_ba(dev, params, false); 818 break; 819 case IEEE80211_AMPDU_TX_START: 820 ssn = mt7615_mac_get_sta_tid_sn(dev, msta->wcid.idx, tid); 821 params->ssn = ssn; 822 ret = IEEE80211_AMPDU_TX_START_IMMEDIATE; 823 break; 824 case IEEE80211_AMPDU_TX_STOP_CONT: 825 mtxq->aggr = false; 826 ret = mt7615_mcu_add_tx_ba(dev, params, false); 827 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); 828 break; 829 } 830 mt7615_mutex_release(dev); 831 832 return ret; 833 } 834 835 static int 836 mt7615_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 837 struct ieee80211_sta *sta) 838 { 839 return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NOTEXIST, 840 IEEE80211_STA_NONE); 841 } 842 843 static int 844 mt7615_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 845 struct ieee80211_sta *sta) 846 { 847 return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NONE, 848 IEEE80211_STA_NOTEXIST); 849 } 850 851 static int 852 mt7615_get_stats(struct ieee80211_hw *hw, 853 struct ieee80211_low_level_stats *stats) 854 { 855 struct mt7615_phy *phy = mt7615_hw_phy(hw); 856 struct mib_stats *mib = &phy->mib; 857 858 mt7615_mutex_acquire(phy->dev); 859 860 stats->dot11RTSSuccessCount = mib->rts_cnt; 861 stats->dot11RTSFailureCount = mib->rts_retries_cnt; 862 stats->dot11FCSErrorCount = mib->fcs_err_cnt; 863 stats->dot11ACKFailureCount = mib->ack_fail_cnt; 864 865 mt7615_mutex_release(phy->dev); 866 867 return 0; 868 } 869 870 static u64 871 mt7615_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 872 { 873 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv; 874 struct mt7615_dev *dev = mt7615_hw_dev(hw); 875 union { 876 u64 t64; 877 u32 t32[2]; 878 } tsf; 879 u16 idx = mvif->mt76.omac_idx; 880 u32 reg; 881 882 idx = idx > HW_BSSID_MAX ? HW_BSSID_0 : idx; 883 reg = idx > 1 ? MT_LPON_TCR2(idx): MT_LPON_TCR0(idx); 884 885 mt7615_mutex_acquire(dev); 886 887 /* TSF read */ 888 mt76_rmw(dev, reg, MT_LPON_TCR_MODE, MT_LPON_TCR_READ); 889 tsf.t32[0] = mt76_rr(dev, MT_LPON_UTTR0); 890 tsf.t32[1] = mt76_rr(dev, MT_LPON_UTTR1); 891 892 mt7615_mutex_release(dev); 893 894 return tsf.t64; 895 } 896 897 static void 898 mt7615_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 899 u64 timestamp) 900 { 901 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv; 902 struct mt7615_dev *dev = mt7615_hw_dev(hw); 903 union { 904 u64 t64; 905 u32 t32[2]; 906 } tsf = { .t64 = timestamp, }; 907 u16 idx = mvif->mt76.omac_idx; 908 u32 reg; 909 910 idx = idx > HW_BSSID_MAX ? HW_BSSID_0 : idx; 911 reg = idx > 1 ? MT_LPON_TCR2(idx): MT_LPON_TCR0(idx); 912 913 mt7615_mutex_acquire(dev); 914 915 mt76_wr(dev, MT_LPON_UTTR0, tsf.t32[0]); 916 mt76_wr(dev, MT_LPON_UTTR1, tsf.t32[1]); 917 /* TSF software overwrite */ 918 mt76_rmw(dev, reg, MT_LPON_TCR_MODE, MT_LPON_TCR_WRITE); 919 920 mt7615_mutex_release(dev); 921 } 922 923 static void 924 mt7615_offset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 925 s64 timestamp) 926 { 927 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv; 928 struct mt7615_dev *dev = mt7615_hw_dev(hw); 929 union { 930 u64 t64; 931 u32 t32[2]; 932 } tsf = { .t64 = timestamp, }; 933 u16 idx = mvif->mt76.omac_idx; 934 u32 reg; 935 936 idx = idx > HW_BSSID_MAX ? HW_BSSID_0 : idx; 937 reg = idx > 1 ? MT_LPON_TCR2(idx): MT_LPON_TCR0(idx); 938 939 mt7615_mutex_acquire(dev); 940 941 mt76_wr(dev, MT_LPON_UTTR0, tsf.t32[0]); 942 mt76_wr(dev, MT_LPON_UTTR1, tsf.t32[1]); 943 /* TSF software adjust*/ 944 mt76_rmw(dev, reg, MT_LPON_TCR_MODE, MT_LPON_TCR_ADJUST); 945 946 mt7615_mutex_release(dev); 947 } 948 949 static void 950 mt7615_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class) 951 { 952 struct mt7615_phy *phy = mt7615_hw_phy(hw); 953 struct mt7615_dev *dev = phy->dev; 954 955 mt7615_mutex_acquire(dev); 956 phy->coverage_class = max_t(s16, coverage_class, 0); 957 mt7615_mac_set_timing(phy); 958 mt7615_mutex_release(dev); 959 } 960 961 static int 962 mt7615_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) 963 { 964 struct mt7615_dev *dev = mt7615_hw_dev(hw); 965 struct mt7615_phy *phy = mt7615_hw_phy(hw); 966 int max_nss = hweight8(hw->wiphy->available_antennas_tx); 967 bool ext_phy = phy != &dev->phy; 968 969 if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss) 970 return -EINVAL; 971 972 if ((BIT(hweight8(tx_ant)) - 1) != tx_ant) 973 tx_ant = BIT(ffs(tx_ant) - 1) - 1; 974 975 mt7615_mutex_acquire(dev); 976 977 phy->mt76->antenna_mask = tx_ant; 978 if (ext_phy) { 979 if (dev->chainmask == 0xf) 980 tx_ant <<= 2; 981 else 982 tx_ant <<= 1; 983 } 984 phy->mt76->chainmask = tx_ant; 985 986 mt76_set_stream_caps(phy->mt76, true); 987 988 mt7615_mutex_release(dev); 989 990 return 0; 991 } 992 993 static void mt7615_roc_iter(void *priv, u8 *mac, 994 struct ieee80211_vif *vif) 995 { 996 struct mt7615_phy *phy = priv; 997 998 mt7615_mcu_set_roc(phy, vif, NULL, 0); 999 } 1000 1001 void mt7615_roc_work(struct work_struct *work) 1002 { 1003 struct mt7615_phy *phy; 1004 1005 phy = (struct mt7615_phy *)container_of(work, struct mt7615_phy, 1006 roc_work); 1007 1008 if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state)) 1009 return; 1010 1011 mt7615_mutex_acquire(phy->dev); 1012 ieee80211_iterate_active_interfaces(phy->mt76->hw, 1013 IEEE80211_IFACE_ITER_RESUME_ALL, 1014 mt7615_roc_iter, phy); 1015 mt7615_mutex_release(phy->dev); 1016 ieee80211_remain_on_channel_expired(phy->mt76->hw); 1017 } 1018 1019 void mt7615_roc_timer(struct timer_list *timer) 1020 { 1021 struct mt7615_phy *phy = from_timer(phy, timer, roc_timer); 1022 1023 ieee80211_queue_work(phy->mt76->hw, &phy->roc_work); 1024 } 1025 1026 void mt7615_scan_work(struct work_struct *work) 1027 { 1028 struct mt7615_phy *phy; 1029 1030 phy = (struct mt7615_phy *)container_of(work, struct mt7615_phy, 1031 scan_work.work); 1032 1033 while (true) { 1034 struct mt7615_mcu_rxd *rxd; 1035 struct sk_buff *skb; 1036 1037 spin_lock_bh(&phy->dev->mt76.lock); 1038 skb = __skb_dequeue(&phy->scan_event_list); 1039 spin_unlock_bh(&phy->dev->mt76.lock); 1040 1041 if (!skb) 1042 break; 1043 1044 rxd = (struct mt7615_mcu_rxd *)skb->data; 1045 if (rxd->eid == MCU_EVENT_SCHED_SCAN_DONE) { 1046 ieee80211_sched_scan_results(phy->mt76->hw); 1047 } else if (test_and_clear_bit(MT76_HW_SCANNING, 1048 &phy->mt76->state)) { 1049 struct cfg80211_scan_info info = { 1050 .aborted = false, 1051 }; 1052 1053 ieee80211_scan_completed(phy->mt76->hw, &info); 1054 } 1055 dev_kfree_skb(skb); 1056 } 1057 } 1058 1059 static int 1060 mt7615_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1061 struct ieee80211_scan_request *req) 1062 { 1063 struct mt7615_dev *dev = mt7615_hw_dev(hw); 1064 struct mt76_phy *mphy = hw->priv; 1065 int err; 1066 1067 /* fall-back to sw-scan */ 1068 if (!mt7615_firmware_offload(dev)) 1069 return 1; 1070 1071 mt7615_mutex_acquire(dev); 1072 err = mt76_connac_mcu_hw_scan(mphy, vif, req); 1073 mt7615_mutex_release(dev); 1074 1075 return err; 1076 } 1077 1078 static void 1079 mt7615_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 1080 { 1081 struct mt7615_dev *dev = mt7615_hw_dev(hw); 1082 struct mt76_phy *mphy = hw->priv; 1083 1084 mt7615_mutex_acquire(dev); 1085 mt76_connac_mcu_cancel_hw_scan(mphy, vif); 1086 mt7615_mutex_release(dev); 1087 } 1088 1089 static int 1090 mt7615_start_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1091 struct cfg80211_sched_scan_request *req, 1092 struct ieee80211_scan_ies *ies) 1093 { 1094 struct mt7615_dev *dev = mt7615_hw_dev(hw); 1095 struct mt76_phy *mphy = hw->priv; 1096 int err; 1097 1098 if (!mt7615_firmware_offload(dev)) 1099 return -EOPNOTSUPP; 1100 1101 mt7615_mutex_acquire(dev); 1102 1103 err = mt76_connac_mcu_sched_scan_req(mphy, vif, req); 1104 if (err < 0) 1105 goto out; 1106 1107 err = mt76_connac_mcu_sched_scan_enable(mphy, vif, true); 1108 out: 1109 mt7615_mutex_release(dev); 1110 1111 return err; 1112 } 1113 1114 static int 1115 mt7615_stop_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 1116 { 1117 struct mt7615_dev *dev = mt7615_hw_dev(hw); 1118 struct mt76_phy *mphy = hw->priv; 1119 int err; 1120 1121 if (!mt7615_firmware_offload(dev)) 1122 return -EOPNOTSUPP; 1123 1124 mt7615_mutex_acquire(dev); 1125 err = mt76_connac_mcu_sched_scan_enable(mphy, vif, false); 1126 mt7615_mutex_release(dev); 1127 1128 return err; 1129 } 1130 1131 static int mt7615_remain_on_channel(struct ieee80211_hw *hw, 1132 struct ieee80211_vif *vif, 1133 struct ieee80211_channel *chan, 1134 int duration, 1135 enum ieee80211_roc_type type) 1136 { 1137 struct mt7615_phy *phy = mt7615_hw_phy(hw); 1138 int err; 1139 1140 if (test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state)) 1141 return 0; 1142 1143 mt7615_mutex_acquire(phy->dev); 1144 1145 err = mt7615_mcu_set_roc(phy, vif, chan, duration); 1146 if (err < 0) { 1147 clear_bit(MT76_STATE_ROC, &phy->mt76->state); 1148 goto out; 1149 } 1150 1151 if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, HZ)) { 1152 mt7615_mcu_set_roc(phy, vif, NULL, 0); 1153 clear_bit(MT76_STATE_ROC, &phy->mt76->state); 1154 err = -ETIMEDOUT; 1155 } 1156 1157 out: 1158 mt7615_mutex_release(phy->dev); 1159 1160 return err; 1161 } 1162 1163 static int mt7615_cancel_remain_on_channel(struct ieee80211_hw *hw, 1164 struct ieee80211_vif *vif) 1165 { 1166 struct mt7615_phy *phy = mt7615_hw_phy(hw); 1167 int err; 1168 1169 if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state)) 1170 return 0; 1171 1172 del_timer_sync(&phy->roc_timer); 1173 cancel_work_sync(&phy->roc_work); 1174 1175 mt7615_mutex_acquire(phy->dev); 1176 err = mt7615_mcu_set_roc(phy, vif, NULL, 0); 1177 mt7615_mutex_release(phy->dev); 1178 1179 return err; 1180 } 1181 1182 static void mt7615_sta_set_decap_offload(struct ieee80211_hw *hw, 1183 struct ieee80211_vif *vif, 1184 struct ieee80211_sta *sta, 1185 bool enabled) 1186 { 1187 struct mt7615_dev *dev = mt7615_hw_dev(hw); 1188 struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv; 1189 1190 if (enabled) 1191 set_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags); 1192 else 1193 clear_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags); 1194 1195 mt7615_mcu_set_sta_decap_offload(dev, vif, sta); 1196 } 1197 1198 #ifdef CONFIG_PM 1199 static int mt7615_suspend(struct ieee80211_hw *hw, 1200 struct cfg80211_wowlan *wowlan) 1201 { 1202 struct mt7615_phy *phy = mt7615_hw_phy(hw); 1203 struct mt7615_dev *dev = mt7615_hw_dev(hw); 1204 int err = 0; 1205 1206 cancel_delayed_work_sync(&dev->pm.ps_work); 1207 mt76_connac_free_pending_tx_skbs(&dev->pm, NULL); 1208 1209 mt7615_mutex_acquire(dev); 1210 1211 clear_bit(MT76_STATE_RUNNING, &phy->mt76->state); 1212 cancel_delayed_work_sync(&phy->scan_work); 1213 cancel_delayed_work_sync(&phy->mt76->mac_work); 1214 1215 set_bit(MT76_STATE_SUSPEND, &phy->mt76->state); 1216 ieee80211_iterate_active_interfaces(hw, 1217 IEEE80211_IFACE_ITER_RESUME_ALL, 1218 mt76_connac_mcu_set_suspend_iter, 1219 phy->mt76); 1220 1221 if (!mt7615_dev_running(dev)) 1222 err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, true); 1223 1224 mt7615_mutex_release(dev); 1225 1226 return err; 1227 } 1228 1229 static int mt7615_resume(struct ieee80211_hw *hw) 1230 { 1231 struct mt7615_phy *phy = mt7615_hw_phy(hw); 1232 struct mt7615_dev *dev = mt7615_hw_dev(hw); 1233 unsigned long timeout; 1234 bool running; 1235 1236 mt7615_mutex_acquire(dev); 1237 1238 running = mt7615_dev_running(dev); 1239 set_bit(MT76_STATE_RUNNING, &phy->mt76->state); 1240 1241 if (!running) { 1242 int err; 1243 1244 err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, false); 1245 if (err < 0) { 1246 mt7615_mutex_release(dev); 1247 return err; 1248 } 1249 } 1250 1251 clear_bit(MT76_STATE_SUSPEND, &phy->mt76->state); 1252 ieee80211_iterate_active_interfaces(hw, 1253 IEEE80211_IFACE_ITER_RESUME_ALL, 1254 mt76_connac_mcu_set_suspend_iter, 1255 phy->mt76); 1256 1257 timeout = mt7615_get_macwork_timeout(dev); 1258 ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work, timeout); 1259 1260 mt7615_mutex_release(dev); 1261 1262 return 0; 1263 } 1264 1265 static void mt7615_set_wakeup(struct ieee80211_hw *hw, bool enabled) 1266 { 1267 struct mt7615_dev *dev = mt7615_hw_dev(hw); 1268 struct mt76_dev *mdev = &dev->mt76; 1269 1270 device_set_wakeup_enable(mdev->dev, enabled); 1271 } 1272 1273 static void mt7615_set_rekey_data(struct ieee80211_hw *hw, 1274 struct ieee80211_vif *vif, 1275 struct cfg80211_gtk_rekey_data *data) 1276 { 1277 struct mt7615_dev *dev = mt7615_hw_dev(hw); 1278 1279 mt7615_mutex_acquire(dev); 1280 mt76_connac_mcu_update_gtk_rekey(hw, vif, data); 1281 mt7615_mutex_release(dev); 1282 } 1283 #endif /* CONFIG_PM */ 1284 1285 const struct ieee80211_ops mt7615_ops = { 1286 .tx = mt7615_tx, 1287 .start = mt7615_start, 1288 .stop = mt7615_stop, 1289 .add_interface = mt7615_add_interface, 1290 .remove_interface = mt7615_remove_interface, 1291 .config = mt7615_config, 1292 .conf_tx = mt7615_conf_tx, 1293 .configure_filter = mt7615_configure_filter, 1294 .bss_info_changed = mt7615_bss_info_changed, 1295 .sta_add = mt7615_sta_add, 1296 .sta_remove = mt7615_sta_remove, 1297 .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove, 1298 .set_key = mt7615_set_key, 1299 .sta_set_decap_offload = mt7615_sta_set_decap_offload, 1300 .ampdu_action = mt7615_ampdu_action, 1301 .set_rts_threshold = mt7615_set_rts_threshold, 1302 .wake_tx_queue = mt76_wake_tx_queue, 1303 .sta_rate_tbl_update = mt7615_sta_rate_tbl_update, 1304 .sw_scan_start = mt76_sw_scan, 1305 .sw_scan_complete = mt76_sw_scan_complete, 1306 .release_buffered_frames = mt76_release_buffered_frames, 1307 .get_txpower = mt76_get_txpower, 1308 .channel_switch_beacon = mt7615_channel_switch_beacon, 1309 .get_stats = mt7615_get_stats, 1310 .get_tsf = mt7615_get_tsf, 1311 .set_tsf = mt7615_set_tsf, 1312 .offset_tsf = mt7615_offset_tsf, 1313 .get_survey = mt76_get_survey, 1314 .get_antenna = mt76_get_antenna, 1315 .set_antenna = mt7615_set_antenna, 1316 .set_coverage_class = mt7615_set_coverage_class, 1317 .hw_scan = mt7615_hw_scan, 1318 .cancel_hw_scan = mt7615_cancel_hw_scan, 1319 .sched_scan_start = mt7615_start_sched_scan, 1320 .sched_scan_stop = mt7615_stop_sched_scan, 1321 .remain_on_channel = mt7615_remain_on_channel, 1322 .cancel_remain_on_channel = mt7615_cancel_remain_on_channel, 1323 CFG80211_TESTMODE_CMD(mt76_testmode_cmd) 1324 CFG80211_TESTMODE_DUMP(mt76_testmode_dump) 1325 #ifdef CONFIG_PM 1326 .suspend = mt7615_suspend, 1327 .resume = mt7615_resume, 1328 .set_wakeup = mt7615_set_wakeup, 1329 .set_rekey_data = mt7615_set_rekey_data, 1330 #endif /* CONFIG_PM */ 1331 }; 1332 EXPORT_SYMBOL_GPL(mt7615_ops); 1333 1334 MODULE_LICENSE("Dual BSD/GPL"); 1335