1 // SPDX-License-Identifier: ISC
2 /* Copyright (C) 2020 MediaTek Inc. */
4 #include <linux/etherdevice.h>
5 #include <linux/platform_device.h>
7 #include <linux/module.h>
11 static bool mt7915_dev_running(struct mt7915_dev *dev)
13 struct mt7915_phy *phy;
15 if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state))
18 phy = mt7915_ext_phy(dev);
20 return phy && test_bit(MT76_STATE_RUNNING, &phy->mt76->state);
23 static int mt7915_start(struct ieee80211_hw *hw)
25 struct mt7915_dev *dev = mt7915_hw_dev(hw);
26 struct mt7915_phy *phy = mt7915_hw_phy(hw);
30 flush_work(&dev->init_work);
32 mutex_lock(&dev->mt76.mutex);
34 running = mt7915_dev_running(dev);
37 ret = mt7915_mcu_set_pm(dev, 0, 0);
41 ret = mt7915_mcu_set_mac(dev, 0, true, true);
45 ret = mt7915_mcu_set_scs(dev, 0, true);
49 mt7915_mac_enable_nf(dev, 0);
52 if (phy != &dev->phy) {
53 ret = mt7915_mcu_set_pm(dev, 1, 0);
57 ret = mt7915_mcu_set_mac(dev, 1, true, true);
61 ret = mt7915_mcu_set_scs(dev, 1, true);
65 mt7915_mac_enable_nf(dev, 1);
68 ret = mt7915_mcu_set_rts_thresh(phy, 0x92b);
72 ret = mt7915_mcu_set_sku_en(phy, true);
76 ret = mt7915_mcu_set_chan_info(phy, MCU_EXT_CMD(SET_RX_PATH));
80 set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
82 if (!mt76_testmode_enabled(phy->mt76))
83 ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
84 MT7915_WATCHDOG_TIME);
87 mt7915_mac_reset_counters(phy);
90 mutex_unlock(&dev->mt76.mutex);
95 static void mt7915_stop(struct ieee80211_hw *hw)
97 struct mt7915_dev *dev = mt7915_hw_dev(hw);
98 struct mt7915_phy *phy = mt7915_hw_phy(hw);
100 cancel_delayed_work_sync(&phy->mt76->mac_work);
102 mutex_lock(&dev->mt76.mutex);
104 mt76_testmode_reset(phy->mt76, true);
106 clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
108 if (phy != &dev->phy) {
109 mt7915_mcu_set_pm(dev, 1, 1);
110 mt7915_mcu_set_mac(dev, 1, false, false);
113 if (!mt7915_dev_running(dev)) {
114 mt7915_mcu_set_pm(dev, 0, 1);
115 mt7915_mcu_set_mac(dev, 0, false, false);
118 mutex_unlock(&dev->mt76.mutex);
121 static inline int get_free_idx(u32 mask, u8 start, u8 end)
123 return ffs(~mask & GENMASK(end, start));
126 static int get_omac_idx(enum nl80211_iftype type, u64 mask)
131 case NL80211_IFTYPE_MESH_POINT:
132 case NL80211_IFTYPE_ADHOC:
133 case NL80211_IFTYPE_STATION:
134 /* prefer hw bssid slot 1-3 */
135 i = get_free_idx(mask, HW_BSSID_1, HW_BSSID_3);
139 if (type != NL80211_IFTYPE_STATION)
142 /* next, try to find a free repeater entry for the sta */
143 i = get_free_idx(mask >> REPEATER_BSSID_START, 0,
144 REPEATER_BSSID_MAX - REPEATER_BSSID_START);
148 i = get_free_idx(mask, EXT_BSSID_1, EXT_BSSID_MAX);
152 if (~mask & BIT(HW_BSSID_0))
156 case NL80211_IFTYPE_MONITOR:
157 case NL80211_IFTYPE_AP:
158 /* ap uses hw bssid 0 and ext bssid */
159 if (~mask & BIT(HW_BSSID_0))
162 i = get_free_idx(mask, EXT_BSSID_1, EXT_BSSID_MAX);
175 static int mt7915_add_interface(struct ieee80211_hw *hw,
176 struct ieee80211_vif *vif)
178 struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
179 struct mt7915_dev *dev = mt7915_hw_dev(hw);
180 struct mt7915_phy *phy = mt7915_hw_phy(hw);
181 struct mt76_txq *mtxq;
182 bool ext_phy = phy != &dev->phy;
185 mutex_lock(&dev->mt76.mutex);
187 mt76_testmode_reset(phy->mt76, true);
189 if (vif->type == NL80211_IFTYPE_MONITOR &&
190 is_zero_ether_addr(vif->addr))
191 phy->monitor_vif = vif;
193 mvif->idx = ffs(~dev->mt76.vif_mask) - 1;
194 if (mvif->idx >= MT7915_MAX_INTERFACES) {
199 idx = get_omac_idx(vif->type, phy->omac_mask);
204 mvif->omac_idx = idx;
206 mvif->band_idx = ext_phy;
209 mvif->wmm_idx = ext_phy * (MT7915_MAX_WMM_SETS / 2) +
210 mvif->idx % (MT7915_MAX_WMM_SETS / 2);
212 mvif->wmm_idx = mvif->idx % MT7915_MAX_WMM_SETS;
214 ret = mt7915_mcu_add_dev_info(phy, vif, true);
218 dev->mt76.vif_mask |= BIT(mvif->idx);
219 phy->omac_mask |= BIT_ULL(mvif->omac_idx);
221 idx = MT7915_WTBL_RESERVED - mvif->idx;
223 INIT_LIST_HEAD(&mvif->sta.rc_list);
224 INIT_LIST_HEAD(&mvif->sta.stats_list);
225 INIT_LIST_HEAD(&mvif->sta.poll_list);
226 mvif->sta.wcid.idx = idx;
227 mvif->sta.wcid.ext_phy = mvif->band_idx;
228 mvif->sta.wcid.hw_key_idx = -1;
229 mvif->sta.wcid.tx_info |= MT_WCID_TX_INFO_SET;
230 mt7915_mac_wtbl_update(dev, idx,
231 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
233 rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid);
235 mtxq = (struct mt76_txq *)vif->txq->drv_priv;
236 mtxq->wcid = &mvif->sta.wcid;
239 if (vif->type != NL80211_IFTYPE_AP &&
240 (!mvif->omac_idx || mvif->omac_idx > 3))
241 vif->offload_flags = 0;
242 vif->offload_flags |= IEEE80211_OFFLOAD_ENCAP_4ADDR;
245 mutex_unlock(&dev->mt76.mutex);
250 static void mt7915_remove_interface(struct ieee80211_hw *hw,
251 struct ieee80211_vif *vif)
253 struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
254 struct mt7915_sta *msta = &mvif->sta;
255 struct mt7915_dev *dev = mt7915_hw_dev(hw);
256 struct mt7915_phy *phy = mt7915_hw_phy(hw);
257 int idx = msta->wcid.idx;
259 mt7915_mcu_add_bss_info(phy, vif, false);
260 mt7915_mcu_add_sta(dev, vif, NULL, false);
262 mutex_lock(&dev->mt76.mutex);
263 mt76_testmode_reset(phy->mt76, true);
264 mutex_unlock(&dev->mt76.mutex);
266 if (vif == phy->monitor_vif)
267 phy->monitor_vif = NULL;
269 mt7915_mcu_add_dev_info(phy, vif, false);
271 rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
273 mutex_lock(&dev->mt76.mutex);
274 dev->mt76.vif_mask &= ~BIT(mvif->idx);
275 phy->omac_mask &= ~BIT_ULL(mvif->omac_idx);
276 mutex_unlock(&dev->mt76.mutex);
278 spin_lock_bh(&dev->sta_poll_lock);
279 if (!list_empty(&msta->poll_list))
280 list_del_init(&msta->poll_list);
281 spin_unlock_bh(&dev->sta_poll_lock);
284 static void mt7915_init_dfs_state(struct mt7915_phy *phy)
286 struct mt76_phy *mphy = phy->mt76;
287 struct ieee80211_hw *hw = mphy->hw;
288 struct cfg80211_chan_def *chandef = &hw->conf.chandef;
290 if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
293 if (!(chandef->chan->flags & IEEE80211_CHAN_RADAR))
296 if (mphy->chandef.chan->center_freq == chandef->chan->center_freq &&
297 mphy->chandef.width == chandef->width)
303 int mt7915_set_channel(struct mt7915_phy *phy)
305 struct mt7915_dev *dev = phy->dev;
308 cancel_delayed_work_sync(&phy->mt76->mac_work);
310 mutex_lock(&dev->mt76.mutex);
311 set_bit(MT76_RESET, &phy->mt76->state);
313 mt7915_init_dfs_state(phy);
314 mt76_set_channel(phy->mt76);
316 if (dev->flash_mode) {
317 ret = mt7915_mcu_apply_tx_dpd(phy);
322 ret = mt7915_mcu_set_chan_info(phy, MCU_EXT_CMD(CHANNEL_SWITCH));
326 mt7915_mac_set_timing(phy);
327 ret = mt7915_dfs_init_radar_detector(phy);
328 mt7915_mac_cca_stats_reset(phy);
330 mt7915_mac_reset_counters(phy);
334 clear_bit(MT76_RESET, &phy->mt76->state);
335 mutex_unlock(&dev->mt76.mutex);
337 mt76_txq_schedule_all(phy->mt76);
339 if (!mt76_testmode_enabled(phy->mt76))
340 ieee80211_queue_delayed_work(phy->mt76->hw,
341 &phy->mt76->mac_work,
342 MT7915_WATCHDOG_TIME);
347 static int mt7915_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
348 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
349 struct ieee80211_key_conf *key)
351 struct mt7915_dev *dev = mt7915_hw_dev(hw);
352 struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
353 struct mt7915_sta *msta = sta ? (struct mt7915_sta *)sta->drv_priv :
355 struct mt76_wcid *wcid = &msta->wcid;
356 u8 *wcid_keyidx = &wcid->hw_key_idx;
357 int idx = key->keyidx;
360 /* The hardware does not support per-STA RX GTK, fallback
361 * to software mode for these.
363 if ((vif->type == NL80211_IFTYPE_ADHOC ||
364 vif->type == NL80211_IFTYPE_MESH_POINT) &&
365 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
366 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
367 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
370 /* fall back to sw encryption for unsupported ciphers */
371 switch (key->cipher) {
372 case WLAN_CIPHER_SUITE_AES_CMAC:
373 wcid_keyidx = &wcid->hw_key_idx2;
374 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
376 case WLAN_CIPHER_SUITE_TKIP:
377 case WLAN_CIPHER_SUITE_CCMP:
378 case WLAN_CIPHER_SUITE_CCMP_256:
379 case WLAN_CIPHER_SUITE_GCMP:
380 case WLAN_CIPHER_SUITE_GCMP_256:
381 case WLAN_CIPHER_SUITE_SMS4:
383 case WLAN_CIPHER_SUITE_WEP40:
384 case WLAN_CIPHER_SUITE_WEP104:
389 mutex_lock(&dev->mt76.mutex);
393 else if (idx == *wcid_keyidx)
398 mt76_wcid_key_setup(&dev->mt76, wcid,
399 cmd == SET_KEY ? key : NULL);
401 err = mt7915_mcu_add_key(dev, vif, msta, key, cmd);
404 mutex_unlock(&dev->mt76.mutex);
409 static int mt7915_config(struct ieee80211_hw *hw, u32 changed)
411 struct mt7915_dev *dev = mt7915_hw_dev(hw);
412 struct mt7915_phy *phy = mt7915_hw_phy(hw);
413 bool band = phy != &dev->phy;
416 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
417 #ifdef CONFIG_NL80211_TESTMODE
418 if (phy->mt76->test.state != MT76_TM_STATE_OFF) {
419 mutex_lock(&dev->mt76.mutex);
420 mt76_testmode_reset(phy->mt76, false);
421 mutex_unlock(&dev->mt76.mutex);
424 ieee80211_stop_queues(hw);
425 ret = mt7915_set_channel(phy);
428 ieee80211_wake_queues(hw);
431 if (changed & IEEE80211_CONF_CHANGE_POWER) {
432 ret = mt7915_mcu_set_txpower_sku(phy);
437 mutex_lock(&dev->mt76.mutex);
439 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
440 bool enabled = !!(hw->conf.flags & IEEE80211_CONF_MONITOR);
443 phy->rxfilter |= MT_WF_RFCR_DROP_OTHER_UC;
445 phy->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_UC;
447 mt76_rmw_field(dev, MT_DMA_DCR0(band), MT_DMA_DCR0_RXD_G5_EN,
449 mt76_testmode_reset(phy->mt76, true);
450 mt76_wr(dev, MT_WF_RFCR(band), phy->rxfilter);
453 mutex_unlock(&dev->mt76.mutex);
459 mt7915_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
460 const struct ieee80211_tx_queue_params *params)
462 struct mt7915_dev *dev = mt7915_hw_dev(hw);
463 struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
465 /* no need to update right away, we'll get BSS_CHANGED_QOS */
466 queue = mt7915_lmac_mapping(dev, queue);
467 mvif->queue_params[queue] = *params;
472 static void mt7915_configure_filter(struct ieee80211_hw *hw,
473 unsigned int changed_flags,
474 unsigned int *total_flags,
477 struct mt7915_dev *dev = mt7915_hw_dev(hw);
478 struct mt7915_phy *phy = mt7915_hw_phy(hw);
479 bool band = phy != &dev->phy;
480 u32 ctl_flags = MT_WF_RFCR1_DROP_ACK |
481 MT_WF_RFCR1_DROP_BF_POLL |
482 MT_WF_RFCR1_DROP_BA |
483 MT_WF_RFCR1_DROP_CFEND |
484 MT_WF_RFCR1_DROP_CFACK;
487 #define MT76_FILTER(_flag, _hw) do { \
488 flags |= *total_flags & FIF_##_flag; \
489 phy->rxfilter &= ~(_hw); \
490 phy->rxfilter |= !(flags & FIF_##_flag) * (_hw); \
493 mutex_lock(&dev->mt76.mutex);
495 phy->rxfilter &= ~(MT_WF_RFCR_DROP_OTHER_BSS |
496 MT_WF_RFCR_DROP_OTHER_BEACON |
497 MT_WF_RFCR_DROP_FRAME_REPORT |
498 MT_WF_RFCR_DROP_PROBEREQ |
499 MT_WF_RFCR_DROP_MCAST_FILTERED |
500 MT_WF_RFCR_DROP_MCAST |
501 MT_WF_RFCR_DROP_BCAST |
502 MT_WF_RFCR_DROP_DUPLICATE |
503 MT_WF_RFCR_DROP_A2_BSSID |
504 MT_WF_RFCR_DROP_UNWANTED_CTL |
505 MT_WF_RFCR_DROP_STBC_MULTI);
507 MT76_FILTER(OTHER_BSS, MT_WF_RFCR_DROP_OTHER_TIM |
508 MT_WF_RFCR_DROP_A3_MAC |
509 MT_WF_RFCR_DROP_A3_BSSID);
511 MT76_FILTER(FCSFAIL, MT_WF_RFCR_DROP_FCSFAIL);
513 MT76_FILTER(CONTROL, MT_WF_RFCR_DROP_CTS |
514 MT_WF_RFCR_DROP_RTS |
515 MT_WF_RFCR_DROP_CTL_RSV |
516 MT_WF_RFCR_DROP_NDPA);
518 *total_flags = flags;
519 mt76_wr(dev, MT_WF_RFCR(band), phy->rxfilter);
521 if (*total_flags & FIF_CONTROL)
522 mt76_clear(dev, MT_WF_RFCR1(band), ctl_flags);
524 mt76_set(dev, MT_WF_RFCR1(band), ctl_flags);
526 mutex_unlock(&dev->mt76.mutex);
529 static void mt7915_bss_info_changed(struct ieee80211_hw *hw,
530 struct ieee80211_vif *vif,
531 struct ieee80211_bss_conf *info,
534 struct mt7915_phy *phy = mt7915_hw_phy(hw);
535 struct mt7915_dev *dev = mt7915_hw_dev(hw);
537 mutex_lock(&dev->mt76.mutex);
540 * station mode uses BSSID to map the wlan entry to a peer,
541 * and then peer references bss_info_rfch to set bandwidth cap.
543 if (changed & BSS_CHANGED_BSSID &&
544 vif->type == NL80211_IFTYPE_STATION) {
545 bool join = !is_zero_ether_addr(info->bssid);
547 mt7915_mcu_add_bss_info(phy, vif, join);
548 mt7915_mcu_add_sta(dev, vif, NULL, join);
551 if (changed & BSS_CHANGED_ASSOC) {
552 mt7915_mcu_add_bss_info(phy, vif, info->assoc);
553 mt7915_mcu_add_obss_spr(dev, vif, info->he_obss_pd.enable);
556 if (changed & BSS_CHANGED_ERP_SLOT) {
557 int slottime = info->use_short_slot ? 9 : 20;
559 if (slottime != phy->slottime) {
560 phy->slottime = slottime;
561 mt7915_mac_set_timing(phy);
565 if (changed & BSS_CHANGED_BEACON_ENABLED && info->enable_beacon) {
566 mt7915_mcu_add_bss_info(phy, vif, true);
567 mt7915_mcu_add_sta(dev, vif, NULL, true);
570 /* ensure that enable txcmd_mode after bss_info */
571 if (changed & (BSS_CHANGED_QOS | BSS_CHANGED_BEACON_ENABLED))
572 mt7915_mcu_set_tx(dev, vif);
574 if (changed & BSS_CHANGED_HE_OBSS_PD)
575 mt7915_mcu_add_obss_spr(dev, vif, info->he_obss_pd.enable);
577 if (changed & (BSS_CHANGED_BEACON |
578 BSS_CHANGED_BEACON_ENABLED))
579 mt7915_mcu_add_beacon(hw, vif, info->enable_beacon);
581 mutex_unlock(&dev->mt76.mutex);
585 mt7915_channel_switch_beacon(struct ieee80211_hw *hw,
586 struct ieee80211_vif *vif,
587 struct cfg80211_chan_def *chandef)
589 struct mt7915_dev *dev = mt7915_hw_dev(hw);
591 mutex_lock(&dev->mt76.mutex);
592 mt7915_mcu_add_beacon(hw, vif, true);
593 mutex_unlock(&dev->mt76.mutex);
596 int mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
597 struct ieee80211_sta *sta)
599 struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
600 struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
601 struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
604 idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA - 1);
608 INIT_LIST_HEAD(&msta->rc_list);
609 INIT_LIST_HEAD(&msta->stats_list);
610 INIT_LIST_HEAD(&msta->poll_list);
613 msta->wcid.idx = idx;
614 msta->wcid.ext_phy = mvif->band_idx;
615 msta->wcid.tx_info |= MT_WCID_TX_INFO_SET;
616 msta->stats.jiffies = jiffies;
618 mt7915_mac_wtbl_update(dev, idx,
619 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
621 ret = mt7915_mcu_add_sta(dev, vif, sta, true);
625 return mt7915_mcu_add_sta_adv(dev, vif, sta, true);
628 void mt7915_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
629 struct ieee80211_sta *sta)
631 struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
632 struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
634 mt7915_mcu_add_sta_adv(dev, vif, sta, false);
635 mt7915_mcu_add_sta(dev, vif, sta, false);
637 mt7915_mac_wtbl_update(dev, msta->wcid.idx,
638 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
640 spin_lock_bh(&dev->sta_poll_lock);
641 if (!list_empty(&msta->poll_list))
642 list_del_init(&msta->poll_list);
643 if (!list_empty(&msta->stats_list))
644 list_del_init(&msta->stats_list);
645 if (!list_empty(&msta->rc_list))
646 list_del_init(&msta->rc_list);
647 spin_unlock_bh(&dev->sta_poll_lock);
650 static void mt7915_tx(struct ieee80211_hw *hw,
651 struct ieee80211_tx_control *control,
654 struct mt7915_dev *dev = mt7915_hw_dev(hw);
655 struct mt76_phy *mphy = hw->priv;
656 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
657 struct ieee80211_vif *vif = info->control.vif;
658 struct mt76_wcid *wcid = &dev->mt76.global_wcid;
661 struct mt7915_sta *sta;
663 sta = (struct mt7915_sta *)control->sta->drv_priv;
667 if (vif && !control->sta) {
668 struct mt7915_vif *mvif;
670 mvif = (struct mt7915_vif *)vif->drv_priv;
671 wcid = &mvif->sta.wcid;
674 mt76_tx(mphy, control->sta, wcid, skb);
677 static int mt7915_set_rts_threshold(struct ieee80211_hw *hw, u32 val)
679 struct mt7915_dev *dev = mt7915_hw_dev(hw);
680 struct mt7915_phy *phy = mt7915_hw_phy(hw);
683 mutex_lock(&dev->mt76.mutex);
684 ret = mt7915_mcu_set_rts_thresh(phy, val);
685 mutex_unlock(&dev->mt76.mutex);
691 mt7915_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
692 struct ieee80211_ampdu_params *params)
694 enum ieee80211_ampdu_mlme_action action = params->action;
695 struct mt7915_dev *dev = mt7915_hw_dev(hw);
696 struct ieee80211_sta *sta = params->sta;
697 struct ieee80211_txq *txq = sta->txq[params->tid];
698 struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
699 u16 tid = params->tid;
700 u16 ssn = params->ssn;
701 struct mt76_txq *mtxq;
707 mtxq = (struct mt76_txq *)txq->drv_priv;
709 mutex_lock(&dev->mt76.mutex);
711 case IEEE80211_AMPDU_RX_START:
712 mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, ssn,
714 ret = mt7915_mcu_add_rx_ba(dev, params, true);
716 case IEEE80211_AMPDU_RX_STOP:
717 mt76_rx_aggr_stop(&dev->mt76, &msta->wcid, tid);
718 ret = mt7915_mcu_add_rx_ba(dev, params, false);
720 case IEEE80211_AMPDU_TX_OPERATIONAL:
722 mtxq->send_bar = false;
723 ret = mt7915_mcu_add_tx_ba(dev, params, true);
725 case IEEE80211_AMPDU_TX_STOP_FLUSH:
726 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
728 clear_bit(tid, &msta->ampdu_state);
729 ret = mt7915_mcu_add_tx_ba(dev, params, false);
731 case IEEE80211_AMPDU_TX_START:
732 set_bit(tid, &msta->ampdu_state);
733 ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;
735 case IEEE80211_AMPDU_TX_STOP_CONT:
737 clear_bit(tid, &msta->ampdu_state);
738 ret = mt7915_mcu_add_tx_ba(dev, params, false);
739 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
742 mutex_unlock(&dev->mt76.mutex);
748 mt7915_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
749 struct ieee80211_sta *sta)
751 return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NOTEXIST,
756 mt7915_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
757 struct ieee80211_sta *sta)
759 return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NONE,
760 IEEE80211_STA_NOTEXIST);
764 mt7915_get_stats(struct ieee80211_hw *hw,
765 struct ieee80211_low_level_stats *stats)
767 struct mt7915_phy *phy = mt7915_hw_phy(hw);
768 struct mt7915_dev *dev = mt7915_hw_dev(hw);
769 struct mib_stats *mib = &phy->mib;
771 mutex_lock(&dev->mt76.mutex);
772 stats->dot11RTSSuccessCount = mib->rts_cnt;
773 stats->dot11RTSFailureCount = mib->rts_retries_cnt;
774 stats->dot11FCSErrorCount = mib->fcs_err_cnt;
775 stats->dot11ACKFailureCount = mib->ack_fail_cnt;
777 memset(mib, 0, sizeof(*mib));
779 mutex_unlock(&dev->mt76.mutex);
785 mt7915_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
787 struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
788 struct mt7915_dev *dev = mt7915_hw_dev(hw);
789 struct mt7915_phy *phy = mt7915_hw_phy(hw);
790 bool band = phy != &dev->phy;
797 mutex_lock(&dev->mt76.mutex);
799 n = mvif->omac_idx > HW_BSSID_MAX ? HW_BSSID_0 : mvif->omac_idx;
800 /* TSF software read */
801 mt76_set(dev, MT_LPON_TCR(band, n), MT_LPON_TCR_SW_MODE);
802 tsf.t32[0] = mt76_rr(dev, MT_LPON_UTTR0(band));
803 tsf.t32[1] = mt76_rr(dev, MT_LPON_UTTR1(band));
805 mutex_unlock(&dev->mt76.mutex);
811 mt7915_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
814 struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
815 struct mt7915_dev *dev = mt7915_hw_dev(hw);
816 struct mt7915_phy *phy = mt7915_hw_phy(hw);
817 bool band = phy != &dev->phy;
821 } tsf = { .t64 = timestamp, };
824 mutex_lock(&dev->mt76.mutex);
826 n = mvif->omac_idx > HW_BSSID_MAX ? HW_BSSID_0 : mvif->omac_idx;
827 mt76_wr(dev, MT_LPON_UTTR0(band), tsf.t32[0]);
828 mt76_wr(dev, MT_LPON_UTTR1(band), tsf.t32[1]);
829 /* TSF software overwrite */
830 mt76_set(dev, MT_LPON_TCR(band, n), MT_LPON_TCR_SW_WRITE);
832 mutex_unlock(&dev->mt76.mutex);
836 mt7915_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class)
838 struct mt7915_phy *phy = mt7915_hw_phy(hw);
839 struct mt7915_dev *dev = phy->dev;
841 mutex_lock(&dev->mt76.mutex);
842 phy->coverage_class = max_t(s16, coverage_class, 0);
843 mt7915_mac_set_timing(phy);
844 mutex_unlock(&dev->mt76.mutex);
848 mt7915_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
850 struct mt7915_dev *dev = mt7915_hw_dev(hw);
851 struct mt7915_phy *phy = mt7915_hw_phy(hw);
852 int max_nss = hweight8(hw->wiphy->available_antennas_tx);
853 bool ext_phy = phy != &dev->phy;
855 if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss)
858 if ((BIT(hweight8(tx_ant)) - 1) != tx_ant)
859 tx_ant = BIT(ffs(tx_ant) - 1) - 1;
861 mutex_lock(&dev->mt76.mutex);
863 phy->mt76->antenna_mask = tx_ant;
866 if (dev->chainmask == 0xf)
871 phy->mt76->chainmask = tx_ant;
873 mt76_set_stream_caps(phy->mt76, true);
874 mt7915_set_stream_vht_txbf_caps(phy);
875 mt7915_set_stream_he_caps(phy);
877 mutex_unlock(&dev->mt76.mutex);
882 static void mt7915_sta_statistics(struct ieee80211_hw *hw,
883 struct ieee80211_vif *vif,
884 struct ieee80211_sta *sta,
885 struct station_info *sinfo)
887 struct mt7915_phy *phy = mt7915_hw_phy(hw);
888 struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
889 struct mt7915_sta_stats *stats = &msta->stats;
890 struct rate_info rxrate = {};
892 if (!mt7915_mcu_get_rx_rate(phy, vif, sta, &rxrate)) {
893 sinfo->rxrate = rxrate;
894 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE);
897 if (!stats->tx_rate.legacy && !stats->tx_rate.flags)
900 if (stats->tx_rate.legacy) {
901 sinfo->txrate.legacy = stats->tx_rate.legacy;
903 sinfo->txrate.mcs = stats->tx_rate.mcs;
904 sinfo->txrate.nss = stats->tx_rate.nss;
905 sinfo->txrate.bw = stats->tx_rate.bw;
906 sinfo->txrate.he_gi = stats->tx_rate.he_gi;
907 sinfo->txrate.he_dcm = stats->tx_rate.he_dcm;
908 sinfo->txrate.he_ru_alloc = stats->tx_rate.he_ru_alloc;
910 sinfo->txrate.flags = stats->tx_rate.flags;
911 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
915 mt7915_sta_rc_update(struct ieee80211_hw *hw,
916 struct ieee80211_vif *vif,
917 struct ieee80211_sta *sta,
920 struct mt7915_dev *dev = mt7915_hw_dev(hw);
921 struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
923 spin_lock_bh(&dev->sta_poll_lock);
924 msta->stats.changed |= changed;
925 if (list_empty(&msta->rc_list))
926 list_add_tail(&msta->rc_list, &dev->sta_rc_list);
927 spin_unlock_bh(&dev->sta_poll_lock);
929 ieee80211_queue_work(hw, &dev->rc_work);
932 static void mt7915_sta_set_4addr(struct ieee80211_hw *hw,
933 struct ieee80211_vif *vif,
934 struct ieee80211_sta *sta,
937 struct mt7915_dev *dev = mt7915_hw_dev(hw);
938 struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
941 set_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags);
943 clear_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags);
945 mt7915_mcu_sta_update_hdr_trans(dev, vif, sta);
948 static void mt7915_sta_set_decap_offload(struct ieee80211_hw *hw,
949 struct ieee80211_vif *vif,
950 struct ieee80211_sta *sta,
953 struct mt7915_dev *dev = mt7915_hw_dev(hw);
954 struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
957 set_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags);
959 clear_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags);
961 mt7915_mcu_sta_update_hdr_trans(dev, vif, sta);
964 const struct ieee80211_ops mt7915_ops = {
966 .start = mt7915_start,
968 .add_interface = mt7915_add_interface,
969 .remove_interface = mt7915_remove_interface,
970 .config = mt7915_config,
971 .conf_tx = mt7915_conf_tx,
972 .configure_filter = mt7915_configure_filter,
973 .bss_info_changed = mt7915_bss_info_changed,
974 .sta_add = mt7915_sta_add,
975 .sta_remove = mt7915_sta_remove,
976 .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
977 .sta_rc_update = mt7915_sta_rc_update,
978 .set_key = mt7915_set_key,
979 .ampdu_action = mt7915_ampdu_action,
980 .set_rts_threshold = mt7915_set_rts_threshold,
981 .wake_tx_queue = mt76_wake_tx_queue,
982 .sw_scan_start = mt76_sw_scan,
983 .sw_scan_complete = mt76_sw_scan_complete,
984 .release_buffered_frames = mt76_release_buffered_frames,
985 .get_txpower = mt76_get_txpower,
986 .channel_switch_beacon = mt7915_channel_switch_beacon,
987 .get_stats = mt7915_get_stats,
988 .get_tsf = mt7915_get_tsf,
989 .set_tsf = mt7915_set_tsf,
990 .get_survey = mt76_get_survey,
991 .get_antenna = mt76_get_antenna,
992 .set_antenna = mt7915_set_antenna,
993 .set_coverage_class = mt7915_set_coverage_class,
994 .sta_statistics = mt7915_sta_statistics,
995 .sta_set_4addr = mt7915_sta_set_4addr,
996 .sta_set_decap_offload = mt7915_sta_set_decap_offload,
997 CFG80211_TESTMODE_CMD(mt76_testmode_cmd)
998 CFG80211_TESTMODE_DUMP(mt76_testmode_dump)
999 #ifdef CONFIG_MAC80211_DEBUGFS
1000 .sta_add_debugfs = mt7915_sta_add_debugfs,