16c92544dSBjoern A. Zeeb // SPDX-License-Identifier: ISC
26c92544dSBjoern A. Zeeb /* Copyright (C) 2019 MediaTek Inc.
36c92544dSBjoern A. Zeeb *
46c92544dSBjoern A. Zeeb * Author: Roy Luo <royluo@google.com>
56c92544dSBjoern A. Zeeb * Ryder Lee <ryder.lee@mediatek.com>
66c92544dSBjoern A. Zeeb * Felix Fietkau <nbd@nbd.name>
76c92544dSBjoern A. Zeeb * Lorenzo Bianconi <lorenzo@kernel.org>
86c92544dSBjoern A. Zeeb */
96c92544dSBjoern A. Zeeb
106c92544dSBjoern A. Zeeb #include <linux/etherdevice.h>
116c92544dSBjoern A. Zeeb #include <linux/module.h>
126c92544dSBjoern A. Zeeb #include "mt7615.h"
136c92544dSBjoern A. Zeeb #include "mcu.h"
146c92544dSBjoern A. Zeeb
mt7615_dev_running(struct mt7615_dev * dev)156c92544dSBjoern A. Zeeb static bool mt7615_dev_running(struct mt7615_dev *dev)
166c92544dSBjoern A. Zeeb {
176c92544dSBjoern A. Zeeb struct mt7615_phy *phy;
186c92544dSBjoern A. Zeeb
196c92544dSBjoern A. Zeeb if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state))
206c92544dSBjoern A. Zeeb return true;
216c92544dSBjoern A. Zeeb
226c92544dSBjoern A. Zeeb phy = mt7615_ext_phy(dev);
236c92544dSBjoern A. Zeeb
246c92544dSBjoern A. Zeeb return phy && test_bit(MT76_STATE_RUNNING, &phy->mt76->state);
256c92544dSBjoern A. Zeeb }
266c92544dSBjoern A. Zeeb
mt7615_start(struct ieee80211_hw * hw)276c92544dSBjoern A. Zeeb static int mt7615_start(struct ieee80211_hw *hw)
286c92544dSBjoern A. Zeeb {
296c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
306c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
316c92544dSBjoern A. Zeeb unsigned long timeout;
326c92544dSBjoern A. Zeeb bool running;
336c92544dSBjoern A. Zeeb int ret;
346c92544dSBjoern A. Zeeb
356c92544dSBjoern A. Zeeb if (!mt7615_wait_for_mcu_init(dev))
366c92544dSBjoern A. Zeeb return -EIO;
376c92544dSBjoern A. Zeeb
386c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
396c92544dSBjoern A. Zeeb
406c92544dSBjoern A. Zeeb running = mt7615_dev_running(dev);
416c92544dSBjoern A. Zeeb
426c92544dSBjoern A. Zeeb if (!running) {
436c92544dSBjoern A. Zeeb ret = mt7615_mcu_set_pm(dev, 0, 0);
446c92544dSBjoern A. Zeeb if (ret)
456c92544dSBjoern A. Zeeb goto out;
466c92544dSBjoern A. Zeeb
476c92544dSBjoern A. Zeeb ret = mt76_connac_mcu_set_mac_enable(&dev->mt76, 0, true, false);
486c92544dSBjoern A. Zeeb if (ret)
496c92544dSBjoern A. Zeeb goto out;
506c92544dSBjoern A. Zeeb
516c92544dSBjoern A. Zeeb mt7615_mac_enable_nf(dev, 0);
526c92544dSBjoern A. Zeeb }
536c92544dSBjoern A. Zeeb
546c92544dSBjoern A. Zeeb if (phy != &dev->phy) {
556c92544dSBjoern A. Zeeb ret = mt7615_mcu_set_pm(dev, 1, 0);
566c92544dSBjoern A. Zeeb if (ret)
576c92544dSBjoern A. Zeeb goto out;
586c92544dSBjoern A. Zeeb
596c92544dSBjoern A. Zeeb ret = mt76_connac_mcu_set_mac_enable(&dev->mt76, 1, true, false);
606c92544dSBjoern A. Zeeb if (ret)
616c92544dSBjoern A. Zeeb goto out;
626c92544dSBjoern A. Zeeb
636c92544dSBjoern A. Zeeb mt7615_mac_enable_nf(dev, 1);
646c92544dSBjoern A. Zeeb }
656c92544dSBjoern A. Zeeb
666c92544dSBjoern A. Zeeb if (mt7615_firmware_offload(dev)) {
676c92544dSBjoern A. Zeeb ret = mt76_connac_mcu_set_channel_domain(phy->mt76);
686c92544dSBjoern A. Zeeb if (ret)
696c92544dSBjoern A. Zeeb goto out;
706c92544dSBjoern A. Zeeb
716c92544dSBjoern A. Zeeb ret = mt76_connac_mcu_set_rate_txpower(phy->mt76);
726c92544dSBjoern A. Zeeb if (ret)
736c92544dSBjoern A. Zeeb goto out;
746c92544dSBjoern A. Zeeb }
756c92544dSBjoern A. Zeeb
766c92544dSBjoern A. Zeeb ret = mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD(SET_RX_PATH));
776c92544dSBjoern A. Zeeb if (ret)
786c92544dSBjoern A. Zeeb goto out;
796c92544dSBjoern A. Zeeb
806c92544dSBjoern A. Zeeb set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
816c92544dSBjoern A. Zeeb
826c92544dSBjoern A. Zeeb timeout = mt7615_get_macwork_timeout(dev);
836c92544dSBjoern A. Zeeb ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work, timeout);
846c92544dSBjoern A. Zeeb
856c92544dSBjoern A. Zeeb if (!running)
86cbb3ec25SBjoern A. Zeeb mt7615_mac_reset_counters(phy);
876c92544dSBjoern A. Zeeb
886c92544dSBjoern A. Zeeb out:
896c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
906c92544dSBjoern A. Zeeb
916c92544dSBjoern A. Zeeb return ret;
926c92544dSBjoern A. Zeeb }
936c92544dSBjoern A. Zeeb
mt7615_stop(struct ieee80211_hw * hw,bool suspend)94*8ba4d145SBjoern A. Zeeb static void mt7615_stop(struct ieee80211_hw *hw, bool suspend)
956c92544dSBjoern A. Zeeb {
966c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
976c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
986c92544dSBjoern A. Zeeb
996c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&phy->mt76->mac_work);
1006c92544dSBjoern A. Zeeb del_timer_sync(&phy->roc_timer);
1016c92544dSBjoern A. Zeeb cancel_work_sync(&phy->roc_work);
1026c92544dSBjoern A. Zeeb
1036c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&dev->pm.ps_work);
1046c92544dSBjoern A. Zeeb cancel_work_sync(&dev->pm.wake_work);
1056c92544dSBjoern A. Zeeb
1066c92544dSBjoern A. Zeeb mt76_connac_free_pending_tx_skbs(&dev->pm, NULL);
1076c92544dSBjoern A. Zeeb
1086c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
1096c92544dSBjoern A. Zeeb
1106c92544dSBjoern A. Zeeb mt76_testmode_reset(phy->mt76, true);
1116c92544dSBjoern A. Zeeb
1126c92544dSBjoern A. Zeeb clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
1136c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&phy->scan_work);
1146c92544dSBjoern A. Zeeb
1156c92544dSBjoern A. Zeeb if (phy != &dev->phy) {
1166c92544dSBjoern A. Zeeb mt7615_mcu_set_pm(dev, 1, 1);
1176c92544dSBjoern A. Zeeb mt76_connac_mcu_set_mac_enable(&dev->mt76, 1, false, false);
1186c92544dSBjoern A. Zeeb }
1196c92544dSBjoern A. Zeeb
1206c92544dSBjoern A. Zeeb if (!mt7615_dev_running(dev)) {
1216c92544dSBjoern A. Zeeb mt7615_mcu_set_pm(dev, 0, 1);
1226c92544dSBjoern A. Zeeb mt76_connac_mcu_set_mac_enable(&dev->mt76, 0, false, false);
1236c92544dSBjoern A. Zeeb }
1246c92544dSBjoern A. Zeeb
1256c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
1266c92544dSBjoern A. Zeeb }
1276c92544dSBjoern A. Zeeb
get_free_idx(u32 mask,u8 start,u8 end)1286c92544dSBjoern A. Zeeb static inline int get_free_idx(u32 mask, u8 start, u8 end)
1296c92544dSBjoern A. Zeeb {
1306c92544dSBjoern A. Zeeb return ffs(~mask & GENMASK(end, start));
1316c92544dSBjoern A. Zeeb }
1326c92544dSBjoern A. Zeeb
get_omac_idx(enum nl80211_iftype type,u64 mask)1336c92544dSBjoern A. Zeeb static int get_omac_idx(enum nl80211_iftype type, u64 mask)
1346c92544dSBjoern A. Zeeb {
1356c92544dSBjoern A. Zeeb int i;
1366c92544dSBjoern A. Zeeb
1376c92544dSBjoern A. Zeeb switch (type) {
1386c92544dSBjoern A. Zeeb case NL80211_IFTYPE_STATION:
1396c92544dSBjoern A. Zeeb /* prefer hw bssid slot 1-3 */
1406c92544dSBjoern A. Zeeb i = get_free_idx(mask, HW_BSSID_1, HW_BSSID_3);
1416c92544dSBjoern A. Zeeb if (i)
1426c92544dSBjoern A. Zeeb return i - 1;
1436c92544dSBjoern A. Zeeb
1446c92544dSBjoern A. Zeeb /* next, try to find a free repeater entry for the sta */
1456c92544dSBjoern A. Zeeb i = get_free_idx(mask >> REPEATER_BSSID_START, 0,
1466c92544dSBjoern A. Zeeb REPEATER_BSSID_MAX - REPEATER_BSSID_START);
1476c92544dSBjoern A. Zeeb if (i)
1486c92544dSBjoern A. Zeeb return i + 32 - 1;
1496c92544dSBjoern A. Zeeb
1506c92544dSBjoern A. Zeeb i = get_free_idx(mask, EXT_BSSID_1, EXT_BSSID_MAX);
1516c92544dSBjoern A. Zeeb if (i)
1526c92544dSBjoern A. Zeeb return i - 1;
1536c92544dSBjoern A. Zeeb
1546c92544dSBjoern A. Zeeb if (~mask & BIT(HW_BSSID_0))
1556c92544dSBjoern A. Zeeb return HW_BSSID_0;
1566c92544dSBjoern A. Zeeb
1576c92544dSBjoern A. Zeeb break;
1586c92544dSBjoern A. Zeeb case NL80211_IFTYPE_ADHOC:
1596c92544dSBjoern A. Zeeb case NL80211_IFTYPE_MESH_POINT:
1606c92544dSBjoern A. Zeeb case NL80211_IFTYPE_MONITOR:
1616c92544dSBjoern A. Zeeb case NL80211_IFTYPE_AP:
1626c92544dSBjoern A. Zeeb /* ap uses hw bssid 0 and ext bssid */
1636c92544dSBjoern A. Zeeb if (~mask & BIT(HW_BSSID_0))
1646c92544dSBjoern A. Zeeb return HW_BSSID_0;
1656c92544dSBjoern A. Zeeb
1666c92544dSBjoern A. Zeeb i = get_free_idx(mask, EXT_BSSID_1, EXT_BSSID_MAX);
1676c92544dSBjoern A. Zeeb if (i)
1686c92544dSBjoern A. Zeeb return i - 1;
1696c92544dSBjoern A. Zeeb
1706c92544dSBjoern A. Zeeb break;
1716c92544dSBjoern A. Zeeb default:
1726c92544dSBjoern A. Zeeb WARN_ON(1);
1736c92544dSBjoern A. Zeeb break;
1746c92544dSBjoern A. Zeeb }
1756c92544dSBjoern A. Zeeb
1766c92544dSBjoern A. Zeeb return -1;
1776c92544dSBjoern A. Zeeb }
1786c92544dSBjoern A. Zeeb
mt7615_add_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)1796c92544dSBjoern A. Zeeb static int mt7615_add_interface(struct ieee80211_hw *hw,
1806c92544dSBjoern A. Zeeb struct ieee80211_vif *vif)
1816c92544dSBjoern A. Zeeb {
1826c92544dSBjoern A. Zeeb struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
1836c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
1846c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
1856c92544dSBjoern A. Zeeb struct mt76_txq *mtxq;
1866c92544dSBjoern A. Zeeb bool ext_phy = phy != &dev->phy;
1876c92544dSBjoern A. Zeeb int idx, ret = 0;
1886c92544dSBjoern A. Zeeb
1896c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
1906c92544dSBjoern A. Zeeb
1916c92544dSBjoern A. Zeeb mt76_testmode_reset(phy->mt76, true);
1926c92544dSBjoern A. Zeeb
1936c92544dSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_MONITOR &&
1946c92544dSBjoern A. Zeeb is_zero_ether_addr(vif->addr))
1956c92544dSBjoern A. Zeeb phy->monitor_vif = vif;
1966c92544dSBjoern A. Zeeb
1976c92544dSBjoern A. Zeeb mvif->mt76.idx = __ffs64(~dev->mt76.vif_mask);
1986c92544dSBjoern A. Zeeb if (mvif->mt76.idx >= MT7615_MAX_INTERFACES) {
1996c92544dSBjoern A. Zeeb ret = -ENOSPC;
2006c92544dSBjoern A. Zeeb goto out;
2016c92544dSBjoern A. Zeeb }
2026c92544dSBjoern A. Zeeb
2036c92544dSBjoern A. Zeeb idx = get_omac_idx(vif->type, dev->omac_mask);
2046c92544dSBjoern A. Zeeb if (idx < 0) {
2056c92544dSBjoern A. Zeeb ret = -ENOSPC;
2066c92544dSBjoern A. Zeeb goto out;
2076c92544dSBjoern A. Zeeb }
2086c92544dSBjoern A. Zeeb mvif->mt76.omac_idx = idx;
2096c92544dSBjoern A. Zeeb
2106c92544dSBjoern A. Zeeb mvif->mt76.band_idx = ext_phy;
2116c92544dSBjoern A. Zeeb mvif->mt76.wmm_idx = vif->type != NL80211_IFTYPE_AP;
212*8ba4d145SBjoern A. Zeeb mvif->mt76.wcid = &mvif->sta.wcid;
2136c92544dSBjoern A. Zeeb if (ext_phy)
2146c92544dSBjoern A. Zeeb mvif->mt76.wmm_idx += 2;
2156c92544dSBjoern A. Zeeb
2166c92544dSBjoern A. Zeeb dev->mt76.vif_mask |= BIT_ULL(mvif->mt76.idx);
2176c92544dSBjoern A. Zeeb dev->omac_mask |= BIT_ULL(mvif->mt76.omac_idx);
2186c92544dSBjoern A. Zeeb phy->omac_mask |= BIT_ULL(mvif->mt76.omac_idx);
2196c92544dSBjoern A. Zeeb
2206c92544dSBjoern A. Zeeb ret = mt7615_mcu_set_dbdc(dev);
2216c92544dSBjoern A. Zeeb if (ret)
2226c92544dSBjoern A. Zeeb goto out;
2236c92544dSBjoern A. Zeeb
2246c92544dSBjoern A. Zeeb idx = MT7615_WTBL_RESERVED - mvif->mt76.idx;
2256c92544dSBjoern A. Zeeb
226cbb3ec25SBjoern A. Zeeb INIT_LIST_HEAD(&mvif->sta.wcid.poll_list);
2276c92544dSBjoern A. Zeeb mvif->sta.wcid.idx = idx;
228*8ba4d145SBjoern A. Zeeb mt76_wcid_init(&mvif->sta.wcid, mvif->mt76.band_idx);
2296c92544dSBjoern A. Zeeb
2306c92544dSBjoern A. Zeeb mt7615_mac_wtbl_update(dev, idx,
2316c92544dSBjoern A. Zeeb MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
2326c92544dSBjoern A. Zeeb
2336c92544dSBjoern A. Zeeb rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid);
2346c92544dSBjoern A. Zeeb if (vif->txq) {
2356c92544dSBjoern A. Zeeb mtxq = (struct mt76_txq *)vif->txq->drv_priv;
2366c92544dSBjoern A. Zeeb mtxq->wcid = idx;
2376c92544dSBjoern A. Zeeb }
2386c92544dSBjoern A. Zeeb
2396c92544dSBjoern A. Zeeb ret = mt7615_mcu_add_dev_info(phy, vif, true);
2406c92544dSBjoern A. Zeeb out:
2416c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
2426c92544dSBjoern A. Zeeb
2436c92544dSBjoern A. Zeeb return ret;
2446c92544dSBjoern A. Zeeb }
2456c92544dSBjoern A. Zeeb
mt7615_remove_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)2466c92544dSBjoern A. Zeeb static void mt7615_remove_interface(struct ieee80211_hw *hw,
2476c92544dSBjoern A. Zeeb struct ieee80211_vif *vif)
2486c92544dSBjoern A. Zeeb {
2496c92544dSBjoern A. Zeeb struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
2506c92544dSBjoern A. Zeeb struct mt7615_sta *msta = &mvif->sta;
2516c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
2526c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
2536c92544dSBjoern A. Zeeb int idx = msta->wcid.idx;
2546c92544dSBjoern A. Zeeb
2556c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
2566c92544dSBjoern A. Zeeb
2576c92544dSBjoern A. Zeeb mt7615_mcu_add_bss_info(phy, vif, NULL, false);
2586c92544dSBjoern A. Zeeb mt7615_mcu_sta_add(phy, vif, NULL, false);
2596c92544dSBjoern A. Zeeb
2606c92544dSBjoern A. Zeeb mt76_testmode_reset(phy->mt76, true);
2616c92544dSBjoern A. Zeeb if (vif == phy->monitor_vif)
2626c92544dSBjoern A. Zeeb phy->monitor_vif = NULL;
2636c92544dSBjoern A. Zeeb
2646c92544dSBjoern A. Zeeb mt76_connac_free_pending_tx_skbs(&dev->pm, &msta->wcid);
2656c92544dSBjoern A. Zeeb
2666c92544dSBjoern A. Zeeb mt7615_mcu_add_dev_info(phy, vif, false);
2676c92544dSBjoern A. Zeeb
2686c92544dSBjoern A. Zeeb rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
2696c92544dSBjoern A. Zeeb
2706c92544dSBjoern A. Zeeb dev->mt76.vif_mask &= ~BIT_ULL(mvif->mt76.idx);
2716c92544dSBjoern A. Zeeb dev->omac_mask &= ~BIT_ULL(mvif->mt76.omac_idx);
2726c92544dSBjoern A. Zeeb phy->omac_mask &= ~BIT_ULL(mvif->mt76.omac_idx);
2736c92544dSBjoern A. Zeeb
2746c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
2756c92544dSBjoern A. Zeeb
276cbb3ec25SBjoern A. Zeeb spin_lock_bh(&dev->mt76.sta_poll_lock);
277cbb3ec25SBjoern A. Zeeb if (!list_empty(&msta->wcid.poll_list))
278cbb3ec25SBjoern A. Zeeb list_del_init(&msta->wcid.poll_list);
279cbb3ec25SBjoern A. Zeeb spin_unlock_bh(&dev->mt76.sta_poll_lock);
2806c92544dSBjoern A. Zeeb
281*8ba4d145SBjoern A. Zeeb mt76_wcid_cleanup(&dev->mt76, &mvif->sta.wcid);
2826c92544dSBjoern A. Zeeb }
2836c92544dSBjoern A. Zeeb
mt7615_set_channel(struct mt76_phy * mphy)284*8ba4d145SBjoern A. Zeeb int mt7615_set_channel(struct mt76_phy *mphy)
2856c92544dSBjoern A. Zeeb {
286*8ba4d145SBjoern A. Zeeb struct mt7615_phy *phy = mphy->priv;
2876c92544dSBjoern A. Zeeb struct mt7615_dev *dev = phy->dev;
2886c92544dSBjoern A. Zeeb bool ext_phy = phy != &dev->phy;
2896c92544dSBjoern A. Zeeb int ret;
2906c92544dSBjoern A. Zeeb
291*8ba4d145SBjoern A. Zeeb mt76_connac_pm_wake(mphy, &dev->pm);
2926c92544dSBjoern A. Zeeb
2936c92544dSBjoern A. Zeeb if (is_mt7615(&dev->mt76) && dev->flash_eeprom) {
2946c92544dSBjoern A. Zeeb ret = mt7615_mcu_apply_rx_dcoc(phy);
2956c92544dSBjoern A. Zeeb if (ret)
2966c92544dSBjoern A. Zeeb goto out;
2976c92544dSBjoern A. Zeeb
2986c92544dSBjoern A. Zeeb ret = mt7615_mcu_apply_tx_dpd(phy);
2996c92544dSBjoern A. Zeeb if (ret)
3006c92544dSBjoern A. Zeeb goto out;
3016c92544dSBjoern A. Zeeb }
3026c92544dSBjoern A. Zeeb
3036c92544dSBjoern A. Zeeb ret = mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD(CHANNEL_SWITCH));
3046c92544dSBjoern A. Zeeb if (ret)
3056c92544dSBjoern A. Zeeb goto out;
3066c92544dSBjoern A. Zeeb
3076c92544dSBjoern A. Zeeb mt7615_mac_set_timing(phy);
3086c92544dSBjoern A. Zeeb ret = mt7615_dfs_init_radar_detector(phy);
3096c92544dSBjoern A. Zeeb if (ret)
3106c92544dSBjoern A. Zeeb goto out;
3116c92544dSBjoern A. Zeeb
3126c92544dSBjoern A. Zeeb mt7615_mac_cca_stats_reset(phy);
3136c92544dSBjoern A. Zeeb ret = mt7615_mcu_set_sku_en(phy, true);
3146c92544dSBjoern A. Zeeb if (ret)
3156c92544dSBjoern A. Zeeb goto out;
3166c92544dSBjoern A. Zeeb
317cbb3ec25SBjoern A. Zeeb mt7615_mac_reset_counters(phy);
3186c92544dSBjoern A. Zeeb phy->noise = 0;
3196c92544dSBjoern A. Zeeb phy->chfreq = mt76_rr(dev, MT_CHFREQ(ext_phy));
3206c92544dSBjoern A. Zeeb
3216c92544dSBjoern A. Zeeb out:
322*8ba4d145SBjoern A. Zeeb mt76_connac_power_save_sched(mphy, &dev->pm);
3236c92544dSBjoern A. Zeeb
3246c92544dSBjoern A. Zeeb if (!mt76_testmode_enabled(phy->mt76)) {
3256c92544dSBjoern A. Zeeb unsigned long timeout = mt7615_get_macwork_timeout(dev);
3266c92544dSBjoern A. Zeeb
3276c92544dSBjoern A. Zeeb ieee80211_queue_delayed_work(phy->mt76->hw,
3286c92544dSBjoern A. Zeeb &phy->mt76->mac_work, timeout);
3296c92544dSBjoern A. Zeeb }
3306c92544dSBjoern A. Zeeb
3316c92544dSBjoern A. Zeeb return ret;
3326c92544dSBjoern A. Zeeb }
333*8ba4d145SBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt7615_set_channel);
3346c92544dSBjoern A. Zeeb
mt7615_set_key(struct ieee80211_hw * hw,enum set_key_cmd cmd,struct ieee80211_vif * vif,struct ieee80211_sta * sta,struct ieee80211_key_conf * key)3356c92544dSBjoern A. Zeeb static int mt7615_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3366c92544dSBjoern A. Zeeb struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3376c92544dSBjoern A. Zeeb struct ieee80211_key_conf *key)
3386c92544dSBjoern A. Zeeb {
3396c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
3406c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
3416c92544dSBjoern A. Zeeb struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
3426c92544dSBjoern A. Zeeb struct mt7615_sta *msta = sta ? (struct mt7615_sta *)sta->drv_priv :
3436c92544dSBjoern A. Zeeb &mvif->sta;
3446c92544dSBjoern A. Zeeb struct mt76_wcid *wcid = &msta->wcid;
3456c92544dSBjoern A. Zeeb int idx = key->keyidx, err = 0;
3466c92544dSBjoern A. Zeeb u8 *wcid_keyidx = &wcid->hw_key_idx;
3476c92544dSBjoern A. Zeeb
3486c92544dSBjoern A. Zeeb /* The hardware does not support per-STA RX GTK, fallback
3496c92544dSBjoern A. Zeeb * to software mode for these.
3506c92544dSBjoern A. Zeeb */
3516c92544dSBjoern A. Zeeb if ((vif->type == NL80211_IFTYPE_ADHOC ||
3526c92544dSBjoern A. Zeeb vif->type == NL80211_IFTYPE_MESH_POINT) &&
3536c92544dSBjoern A. Zeeb (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
3546c92544dSBjoern A. Zeeb key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
3556c92544dSBjoern A. Zeeb !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
3566c92544dSBjoern A. Zeeb return -EOPNOTSUPP;
3576c92544dSBjoern A. Zeeb
3586c92544dSBjoern A. Zeeb /* fall back to sw encryption for unsupported ciphers */
3596c92544dSBjoern A. Zeeb switch (key->cipher) {
3606c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC:
3616c92544dSBjoern A. Zeeb wcid_keyidx = &wcid->hw_key_idx2;
3626c92544dSBjoern A. Zeeb key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
3636c92544dSBjoern A. Zeeb break;
3646c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP:
3656c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP:
3666c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256:
3676c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP:
3686c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256:
3696c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_SMS4:
3706c92544dSBjoern A. Zeeb break;
3716c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40:
3726c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104:
3736c92544dSBjoern A. Zeeb default:
3746c92544dSBjoern A. Zeeb return -EOPNOTSUPP;
3756c92544dSBjoern A. Zeeb }
3766c92544dSBjoern A. Zeeb
3776c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
3786c92544dSBjoern A. Zeeb
3796c92544dSBjoern A. Zeeb if (cmd == SET_KEY && !sta && !mvif->mt76.cipher) {
3806c92544dSBjoern A. Zeeb mvif->mt76.cipher = mt76_connac_mcu_get_cipher(key->cipher);
3816c92544dSBjoern A. Zeeb mt7615_mcu_add_bss_info(phy, vif, NULL, true);
3826c92544dSBjoern A. Zeeb }
3836c92544dSBjoern A. Zeeb
3846c92544dSBjoern A. Zeeb if (cmd == SET_KEY)
3856c92544dSBjoern A. Zeeb *wcid_keyidx = idx;
386cbb3ec25SBjoern A. Zeeb else {
387cbb3ec25SBjoern A. Zeeb if (idx == *wcid_keyidx)
3886c92544dSBjoern A. Zeeb *wcid_keyidx = -1;
3896c92544dSBjoern A. Zeeb goto out;
390cbb3ec25SBjoern A. Zeeb }
3916c92544dSBjoern A. Zeeb
392cbb3ec25SBjoern A. Zeeb mt76_wcid_key_setup(&dev->mt76, wcid, key);
3936c92544dSBjoern A. Zeeb if (mt76_is_mmio(&dev->mt76))
394cbb3ec25SBjoern A. Zeeb err = mt7615_mac_wtbl_set_key(dev, wcid, key);
3956c92544dSBjoern A. Zeeb else
396cbb3ec25SBjoern A. Zeeb err = __mt7615_mac_wtbl_set_key(dev, wcid, key);
3976c92544dSBjoern A. Zeeb
3986c92544dSBjoern A. Zeeb out:
3996c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
4006c92544dSBjoern A. Zeeb
4016c92544dSBjoern A. Zeeb return err;
4026c92544dSBjoern A. Zeeb }
4036c92544dSBjoern A. Zeeb
mt7615_set_sar_specs(struct ieee80211_hw * hw,const struct cfg80211_sar_specs * sar)4046c92544dSBjoern A. Zeeb static int mt7615_set_sar_specs(struct ieee80211_hw *hw,
4056c92544dSBjoern A. Zeeb const struct cfg80211_sar_specs *sar)
4066c92544dSBjoern A. Zeeb {
4076c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
4086c92544dSBjoern A. Zeeb int err;
4096c92544dSBjoern A. Zeeb
4106c92544dSBjoern A. Zeeb if (!cfg80211_chandef_valid(&phy->mt76->chandef))
4116c92544dSBjoern A. Zeeb return -EINVAL;
4126c92544dSBjoern A. Zeeb
4136c92544dSBjoern A. Zeeb err = mt76_init_sar_power(hw, sar);
4146c92544dSBjoern A. Zeeb if (err)
4156c92544dSBjoern A. Zeeb return err;
4166c92544dSBjoern A. Zeeb
4176c92544dSBjoern A. Zeeb if (mt7615_firmware_offload(phy->dev))
4186c92544dSBjoern A. Zeeb return mt76_connac_mcu_set_rate_txpower(phy->mt76);
4196c92544dSBjoern A. Zeeb
420*8ba4d145SBjoern A. Zeeb return mt76_update_channel(phy->mt76);
4216c92544dSBjoern A. Zeeb }
4226c92544dSBjoern A. Zeeb
mt7615_config(struct ieee80211_hw * hw,u32 changed)4236c92544dSBjoern A. Zeeb static int mt7615_config(struct ieee80211_hw *hw, u32 changed)
4246c92544dSBjoern A. Zeeb {
4256c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
4266c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
4276c92544dSBjoern A. Zeeb bool band = phy != &dev->phy;
4286c92544dSBjoern A. Zeeb int ret = 0;
4296c92544dSBjoern A. Zeeb
4306c92544dSBjoern A. Zeeb if (changed & (IEEE80211_CONF_CHANGE_CHANNEL |
4316c92544dSBjoern A. Zeeb IEEE80211_CONF_CHANGE_POWER)) {
4326c92544dSBjoern A. Zeeb #ifdef CONFIG_NL80211_TESTMODE
4336c92544dSBjoern A. Zeeb if (phy->mt76->test.state != MT76_TM_STATE_OFF) {
4346c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
4356c92544dSBjoern A. Zeeb mt76_testmode_reset(phy->mt76, false);
4366c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
4376c92544dSBjoern A. Zeeb }
4386c92544dSBjoern A. Zeeb #endif
439*8ba4d145SBjoern A. Zeeb ret = mt76_update_channel(phy->mt76);
4406c92544dSBjoern A. Zeeb }
4416c92544dSBjoern A. Zeeb
4426c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
4436c92544dSBjoern A. Zeeb
4446c92544dSBjoern A. Zeeb if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4456c92544dSBjoern A. Zeeb mt76_testmode_reset(phy->mt76, true);
4466c92544dSBjoern A. Zeeb
4476c92544dSBjoern A. Zeeb if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
4486c92544dSBjoern A. Zeeb phy->rxfilter |= MT_WF_RFCR_DROP_OTHER_UC;
4496c92544dSBjoern A. Zeeb else
4506c92544dSBjoern A. Zeeb phy->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_UC;
4516c92544dSBjoern A. Zeeb
4526c92544dSBjoern A. Zeeb mt76_wr(dev, MT_WF_RFCR(band), phy->rxfilter);
4536c92544dSBjoern A. Zeeb }
4546c92544dSBjoern A. Zeeb
4556c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
4566c92544dSBjoern A. Zeeb
4576c92544dSBjoern A. Zeeb return ret;
4586c92544dSBjoern A. Zeeb }
4596c92544dSBjoern A. Zeeb
4606c92544dSBjoern A. Zeeb static int
mt7615_conf_tx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,unsigned int link_id,u16 queue,const struct ieee80211_tx_queue_params * params)4616c92544dSBjoern A. Zeeb mt7615_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4626c92544dSBjoern A. Zeeb unsigned int link_id, u16 queue,
4636c92544dSBjoern A. Zeeb const struct ieee80211_tx_queue_params *params)
4646c92544dSBjoern A. Zeeb {
465*8ba4d145SBjoern A. Zeeb struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv;
4666c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
4676c92544dSBjoern A. Zeeb int err;
4686c92544dSBjoern A. Zeeb
4696c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
4706c92544dSBjoern A. Zeeb
4716c92544dSBjoern A. Zeeb queue = mt7615_lmac_mapping(dev, queue);
4726c92544dSBjoern A. Zeeb queue += mvif->wmm_idx * MT7615_MAX_WMM_SETS;
4736c92544dSBjoern A. Zeeb err = mt7615_mcu_set_wmm(dev, queue, params);
4746c92544dSBjoern A. Zeeb
4756c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
4766c92544dSBjoern A. Zeeb
4776c92544dSBjoern A. Zeeb return err;
4786c92544dSBjoern A. Zeeb }
4796c92544dSBjoern A. Zeeb
mt7615_configure_filter(struct ieee80211_hw * hw,unsigned int changed_flags,unsigned int * total_flags,u64 multicast)4806c92544dSBjoern A. Zeeb static void mt7615_configure_filter(struct ieee80211_hw *hw,
4816c92544dSBjoern A. Zeeb unsigned int changed_flags,
4826c92544dSBjoern A. Zeeb unsigned int *total_flags,
4836c92544dSBjoern A. Zeeb u64 multicast)
4846c92544dSBjoern A. Zeeb {
4856c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
4866c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
4876c92544dSBjoern A. Zeeb bool band = phy != &dev->phy;
4886c92544dSBjoern A. Zeeb
4896c92544dSBjoern A. Zeeb u32 ctl_flags = MT_WF_RFCR1_DROP_ACK |
4906c92544dSBjoern A. Zeeb MT_WF_RFCR1_DROP_BF_POLL |
4916c92544dSBjoern A. Zeeb MT_WF_RFCR1_DROP_BA |
4926c92544dSBjoern A. Zeeb MT_WF_RFCR1_DROP_CFEND |
4936c92544dSBjoern A. Zeeb MT_WF_RFCR1_DROP_CFACK;
4946c92544dSBjoern A. Zeeb u32 flags = 0;
4956c92544dSBjoern A. Zeeb
4966c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
4976c92544dSBjoern A. Zeeb
4986c92544dSBjoern A. Zeeb #define MT76_FILTER(_flag, _hw) do { \
4996c92544dSBjoern A. Zeeb flags |= *total_flags & FIF_##_flag; \
5006c92544dSBjoern A. Zeeb phy->rxfilter &= ~(_hw); \
5016c92544dSBjoern A. Zeeb if (!mt76_testmode_enabled(phy->mt76)) \
5026c92544dSBjoern A. Zeeb phy->rxfilter |= !(flags & FIF_##_flag) * (_hw);\
5036c92544dSBjoern A. Zeeb } while (0)
5046c92544dSBjoern A. Zeeb
5056c92544dSBjoern A. Zeeb phy->rxfilter &= ~(MT_WF_RFCR_DROP_OTHER_BSS |
5066c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_FRAME_REPORT |
5076c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_PROBEREQ |
5086c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_MCAST_FILTERED |
5096c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_MCAST |
5106c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_BCAST |
5116c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_DUPLICATE |
5126c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_A2_BSSID |
5136c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_UNWANTED_CTL |
5146c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_STBC_MULTI);
5156c92544dSBjoern A. Zeeb
5166c92544dSBjoern A. Zeeb if (phy->n_beacon_vif || !mt7615_firmware_offload(dev))
5176c92544dSBjoern A. Zeeb phy->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_BEACON;
5186c92544dSBjoern A. Zeeb
5196c92544dSBjoern A. Zeeb MT76_FILTER(OTHER_BSS, MT_WF_RFCR_DROP_OTHER_TIM |
5206c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_A3_MAC |
5216c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_A3_BSSID);
5226c92544dSBjoern A. Zeeb
5236c92544dSBjoern A. Zeeb MT76_FILTER(FCSFAIL, MT_WF_RFCR_DROP_FCSFAIL);
5246c92544dSBjoern A. Zeeb
5256c92544dSBjoern A. Zeeb MT76_FILTER(CONTROL, MT_WF_RFCR_DROP_CTS |
5266c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_RTS |
5276c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_CTL_RSV |
5286c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_NDPA);
5296c92544dSBjoern A. Zeeb
5306c92544dSBjoern A. Zeeb *total_flags = flags;
5316c92544dSBjoern A. Zeeb mt76_wr(dev, MT_WF_RFCR(band), phy->rxfilter);
5326c92544dSBjoern A. Zeeb
5336c92544dSBjoern A. Zeeb if (*total_flags & FIF_CONTROL)
5346c92544dSBjoern A. Zeeb mt76_clear(dev, MT_WF_RFCR1(band), ctl_flags);
5356c92544dSBjoern A. Zeeb else
5366c92544dSBjoern A. Zeeb mt76_set(dev, MT_WF_RFCR1(band), ctl_flags);
5376c92544dSBjoern A. Zeeb
5386c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
5396c92544dSBjoern A. Zeeb }
5406c92544dSBjoern A. Zeeb
541cbb3ec25SBjoern A. Zeeb static void
mt7615_update_mu_group(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * info)542cbb3ec25SBjoern A. Zeeb mt7615_update_mu_group(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
543cbb3ec25SBjoern A. Zeeb struct ieee80211_bss_conf *info)
544cbb3ec25SBjoern A. Zeeb {
545cbb3ec25SBjoern A. Zeeb struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
546cbb3ec25SBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
547cbb3ec25SBjoern A. Zeeb u8 i, band = mvif->mt76.band_idx;
548cbb3ec25SBjoern A. Zeeb u32 *mu;
549cbb3ec25SBjoern A. Zeeb
550cbb3ec25SBjoern A. Zeeb mu = (u32 *)info->mu_group.membership;
551cbb3ec25SBjoern A. Zeeb for (i = 0; i < WLAN_MEMBERSHIP_LEN / sizeof(*mu); i++) {
552cbb3ec25SBjoern A. Zeeb if (is_mt7663(&dev->mt76))
553cbb3ec25SBjoern A. Zeeb mt76_wr(dev, MT7663_WF_PHY_GID_TAB_VLD(band, i), mu[i]);
554cbb3ec25SBjoern A. Zeeb else
555cbb3ec25SBjoern A. Zeeb mt76_wr(dev, MT_WF_PHY_GID_TAB_VLD(band, i), mu[i]);
556cbb3ec25SBjoern A. Zeeb }
557cbb3ec25SBjoern A. Zeeb
558cbb3ec25SBjoern A. Zeeb mu = (u32 *)info->mu_group.position;
559cbb3ec25SBjoern A. Zeeb for (i = 0; i < WLAN_USER_POSITION_LEN / sizeof(*mu); i++) {
560cbb3ec25SBjoern A. Zeeb if (is_mt7663(&dev->mt76))
561cbb3ec25SBjoern A. Zeeb mt76_wr(dev, MT7663_WF_PHY_GID_TAB_POS(band, i), mu[i]);
562cbb3ec25SBjoern A. Zeeb else
563cbb3ec25SBjoern A. Zeeb mt76_wr(dev, MT_WF_PHY_GID_TAB_POS(band, i), mu[i]);
564cbb3ec25SBjoern A. Zeeb }
565cbb3ec25SBjoern A. Zeeb }
566cbb3ec25SBjoern A. Zeeb
mt7615_bss_info_changed(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * info,u64 changed)5676c92544dSBjoern A. Zeeb static void mt7615_bss_info_changed(struct ieee80211_hw *hw,
5686c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
5696c92544dSBjoern A. Zeeb struct ieee80211_bss_conf *info,
5706c92544dSBjoern A. Zeeb u64 changed)
5716c92544dSBjoern A. Zeeb {
5726c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
5736c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
5746c92544dSBjoern A. Zeeb
5756c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
5766c92544dSBjoern A. Zeeb
5776c92544dSBjoern A. Zeeb if (changed & BSS_CHANGED_ERP_SLOT) {
5786c92544dSBjoern A. Zeeb int slottime = info->use_short_slot ? 9 : 20;
5796c92544dSBjoern A. Zeeb
5806c92544dSBjoern A. Zeeb if (slottime != phy->slottime) {
5816c92544dSBjoern A. Zeeb phy->slottime = slottime;
5826c92544dSBjoern A. Zeeb mt7615_mac_set_timing(phy);
5836c92544dSBjoern A. Zeeb }
5846c92544dSBjoern A. Zeeb }
5856c92544dSBjoern A. Zeeb
586cbb3ec25SBjoern A. Zeeb if (changed & BSS_CHANGED_ERP_CTS_PROT)
587cbb3ec25SBjoern A. Zeeb mt7615_mac_enable_rtscts(dev, vif, info->use_cts_prot);
588cbb3ec25SBjoern A. Zeeb
5896c92544dSBjoern A. Zeeb if (changed & BSS_CHANGED_BEACON_ENABLED && info->enable_beacon) {
5906c92544dSBjoern A. Zeeb mt7615_mcu_add_bss_info(phy, vif, NULL, true);
5916c92544dSBjoern A. Zeeb mt7615_mcu_sta_add(phy, vif, NULL, true);
5926c92544dSBjoern A. Zeeb
5936c92544dSBjoern A. Zeeb if (mt7615_firmware_offload(dev) && vif->p2p)
5946c92544dSBjoern A. Zeeb mt76_connac_mcu_set_p2p_oppps(hw, vif);
5956c92544dSBjoern A. Zeeb }
5966c92544dSBjoern A. Zeeb
5976c92544dSBjoern A. Zeeb if (changed & (BSS_CHANGED_BEACON |
5986c92544dSBjoern A. Zeeb BSS_CHANGED_BEACON_ENABLED))
5996c92544dSBjoern A. Zeeb mt7615_mcu_add_beacon(dev, hw, vif, info->enable_beacon);
6006c92544dSBjoern A. Zeeb
6016c92544dSBjoern A. Zeeb if (changed & BSS_CHANGED_PS)
6026c92544dSBjoern A. Zeeb mt76_connac_mcu_set_vif_ps(&dev->mt76, vif);
6036c92544dSBjoern A. Zeeb
6046c92544dSBjoern A. Zeeb if ((changed & BSS_CHANGED_ARP_FILTER) &&
6056c92544dSBjoern A. Zeeb mt7615_firmware_offload(dev)) {
6066c92544dSBjoern A. Zeeb struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
6076c92544dSBjoern A. Zeeb
6086c92544dSBjoern A. Zeeb mt76_connac_mcu_update_arp_filter(&dev->mt76, &mvif->mt76,
6096c92544dSBjoern A. Zeeb info);
6106c92544dSBjoern A. Zeeb }
6116c92544dSBjoern A. Zeeb
6126c92544dSBjoern A. Zeeb if (changed & BSS_CHANGED_ASSOC)
6136c92544dSBjoern A. Zeeb mt7615_mac_set_beacon_filter(phy, vif, vif->cfg.assoc);
6146c92544dSBjoern A. Zeeb
615cbb3ec25SBjoern A. Zeeb if (changed & BSS_CHANGED_MU_GROUPS)
616cbb3ec25SBjoern A. Zeeb mt7615_update_mu_group(hw, vif, info);
617cbb3ec25SBjoern A. Zeeb
6186c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
6196c92544dSBjoern A. Zeeb }
6206c92544dSBjoern A. Zeeb
6216c92544dSBjoern A. Zeeb static void
mt7615_channel_switch_beacon(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct cfg80211_chan_def * chandef)6226c92544dSBjoern A. Zeeb mt7615_channel_switch_beacon(struct ieee80211_hw *hw,
6236c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
6246c92544dSBjoern A. Zeeb struct cfg80211_chan_def *chandef)
6256c92544dSBjoern A. Zeeb {
6266c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
6276c92544dSBjoern A. Zeeb
6286c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
6296c92544dSBjoern A. Zeeb mt7615_mcu_add_beacon(dev, hw, vif, true);
6306c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
6316c92544dSBjoern A. Zeeb }
6326c92544dSBjoern A. Zeeb
mt7615_mac_sta_add(struct mt76_dev * mdev,struct ieee80211_vif * vif,struct ieee80211_sta * sta)6336c92544dSBjoern A. Zeeb int mt7615_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
6346c92544dSBjoern A. Zeeb struct ieee80211_sta *sta)
6356c92544dSBjoern A. Zeeb {
6366c92544dSBjoern A. Zeeb struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
6376c92544dSBjoern A. Zeeb struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv;
6386c92544dSBjoern A. Zeeb struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
6396c92544dSBjoern A. Zeeb struct mt7615_phy *phy;
6406c92544dSBjoern A. Zeeb int idx, err;
6416c92544dSBjoern A. Zeeb
6426c92544dSBjoern A. Zeeb idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7615_WTBL_STA - 1);
6436c92544dSBjoern A. Zeeb if (idx < 0)
6446c92544dSBjoern A. Zeeb return -ENOSPC;
6456c92544dSBjoern A. Zeeb
646cbb3ec25SBjoern A. Zeeb INIT_LIST_HEAD(&msta->wcid.poll_list);
6476c92544dSBjoern A. Zeeb msta->vif = mvif;
6486c92544dSBjoern A. Zeeb msta->wcid.sta = 1;
6496c92544dSBjoern A. Zeeb msta->wcid.idx = idx;
6506c92544dSBjoern A. Zeeb msta->wcid.phy_idx = mvif->mt76.band_idx;
6516c92544dSBjoern A. Zeeb
6526c92544dSBjoern A. Zeeb phy = mvif->mt76.band_idx ? mt7615_ext_phy(dev) : &dev->phy;
6536c92544dSBjoern A. Zeeb err = mt76_connac_pm_wake(phy->mt76, &dev->pm);
6546c92544dSBjoern A. Zeeb if (err)
6556c92544dSBjoern A. Zeeb return err;
6566c92544dSBjoern A. Zeeb
6576c92544dSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) {
6586c92544dSBjoern A. Zeeb err = mt7615_mcu_add_bss_info(phy, vif, sta, true);
6596c92544dSBjoern A. Zeeb if (err)
6606c92544dSBjoern A. Zeeb return err;
6616c92544dSBjoern A. Zeeb }
6626c92544dSBjoern A. Zeeb
6636c92544dSBjoern A. Zeeb mt7615_mac_wtbl_update(dev, idx,
6646c92544dSBjoern A. Zeeb MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
6656c92544dSBjoern A. Zeeb err = mt7615_mcu_sta_add(&dev->phy, vif, sta, true);
6666c92544dSBjoern A. Zeeb if (err)
6676c92544dSBjoern A. Zeeb return err;
6686c92544dSBjoern A. Zeeb
6696c92544dSBjoern A. Zeeb mt76_connac_power_save_sched(phy->mt76, &dev->pm);
6706c92544dSBjoern A. Zeeb
6716c92544dSBjoern A. Zeeb return err;
6726c92544dSBjoern A. Zeeb }
6736c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt7615_mac_sta_add);
6746c92544dSBjoern A. Zeeb
mt7615_mac_sta_remove(struct mt76_dev * mdev,struct ieee80211_vif * vif,struct ieee80211_sta * sta)6756c92544dSBjoern A. Zeeb void mt7615_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
6766c92544dSBjoern A. Zeeb struct ieee80211_sta *sta)
6776c92544dSBjoern A. Zeeb {
6786c92544dSBjoern A. Zeeb struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
6796c92544dSBjoern A. Zeeb struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv;
6806c92544dSBjoern A. Zeeb struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
6816c92544dSBjoern A. Zeeb struct mt7615_phy *phy;
6826c92544dSBjoern A. Zeeb
6836c92544dSBjoern A. Zeeb mt76_connac_free_pending_tx_skbs(&dev->pm, &msta->wcid);
6846c92544dSBjoern A. Zeeb
6856c92544dSBjoern A. Zeeb phy = mvif->mt76.band_idx ? mt7615_ext_phy(dev) : &dev->phy;
6866c92544dSBjoern A. Zeeb mt76_connac_pm_wake(phy->mt76, &dev->pm);
6876c92544dSBjoern A. Zeeb
6886c92544dSBjoern A. Zeeb mt7615_mcu_sta_add(&dev->phy, vif, sta, false);
6896c92544dSBjoern A. Zeeb mt7615_mac_wtbl_update(dev, msta->wcid.idx,
6906c92544dSBjoern A. Zeeb MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
6916c92544dSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
6926c92544dSBjoern A. Zeeb mt7615_mcu_add_bss_info(phy, vif, sta, false);
6936c92544dSBjoern A. Zeeb
694cbb3ec25SBjoern A. Zeeb spin_lock_bh(&mdev->sta_poll_lock);
695cbb3ec25SBjoern A. Zeeb if (!list_empty(&msta->wcid.poll_list))
696cbb3ec25SBjoern A. Zeeb list_del_init(&msta->wcid.poll_list);
697cbb3ec25SBjoern A. Zeeb spin_unlock_bh(&mdev->sta_poll_lock);
6986c92544dSBjoern A. Zeeb
6996c92544dSBjoern A. Zeeb mt76_connac_power_save_sched(phy->mt76, &dev->pm);
7006c92544dSBjoern A. Zeeb }
7016c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt7615_mac_sta_remove);
7026c92544dSBjoern A. Zeeb
mt7615_sta_rate_tbl_update(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)7036c92544dSBjoern A. Zeeb static void mt7615_sta_rate_tbl_update(struct ieee80211_hw *hw,
7046c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
7056c92544dSBjoern A. Zeeb struct ieee80211_sta *sta)
7066c92544dSBjoern A. Zeeb {
7076c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
7086c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
7096c92544dSBjoern A. Zeeb struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv;
7106c92544dSBjoern A. Zeeb struct ieee80211_sta_rates *sta_rates = rcu_dereference(sta->rates);
7116c92544dSBjoern A. Zeeb int i;
7126c92544dSBjoern A. Zeeb
7136c92544dSBjoern A. Zeeb if (!sta_rates)
7146c92544dSBjoern A. Zeeb return;
7156c92544dSBjoern A. Zeeb
7166c92544dSBjoern A. Zeeb spin_lock_bh(&dev->mt76.lock);
7176c92544dSBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(msta->rates); i++) {
7186c92544dSBjoern A. Zeeb msta->rates[i].idx = sta_rates->rate[i].idx;
7196c92544dSBjoern A. Zeeb msta->rates[i].count = sta_rates->rate[i].count;
7206c92544dSBjoern A. Zeeb msta->rates[i].flags = sta_rates->rate[i].flags;
7216c92544dSBjoern A. Zeeb
7226c92544dSBjoern A. Zeeb if (msta->rates[i].idx < 0 || !msta->rates[i].count)
7236c92544dSBjoern A. Zeeb break;
7246c92544dSBjoern A. Zeeb }
7256c92544dSBjoern A. Zeeb msta->n_rates = i;
7266c92544dSBjoern A. Zeeb if (mt76_connac_pm_ref(phy->mt76, &dev->pm)) {
7276c92544dSBjoern A. Zeeb mt7615_mac_set_rates(phy, msta, NULL, msta->rates);
7286c92544dSBjoern A. Zeeb mt76_connac_pm_unref(phy->mt76, &dev->pm);
7296c92544dSBjoern A. Zeeb }
7306c92544dSBjoern A. Zeeb spin_unlock_bh(&dev->mt76.lock);
7316c92544dSBjoern A. Zeeb }
7326c92544dSBjoern A. Zeeb
mt7615_tx_worker(struct mt76_worker * w)7336c92544dSBjoern A. Zeeb void mt7615_tx_worker(struct mt76_worker *w)
7346c92544dSBjoern A. Zeeb {
7356c92544dSBjoern A. Zeeb struct mt7615_dev *dev = container_of(w, struct mt7615_dev,
7366c92544dSBjoern A. Zeeb mt76.tx_worker);
7376c92544dSBjoern A. Zeeb
7386c92544dSBjoern A. Zeeb if (!mt76_connac_pm_ref(&dev->mphy, &dev->pm)) {
7396c92544dSBjoern A. Zeeb queue_work(dev->mt76.wq, &dev->pm.wake_work);
7406c92544dSBjoern A. Zeeb return;
7416c92544dSBjoern A. Zeeb }
7426c92544dSBjoern A. Zeeb
7436c92544dSBjoern A. Zeeb mt76_tx_worker_run(&dev->mt76);
7446c92544dSBjoern A. Zeeb mt76_connac_pm_unref(&dev->mphy, &dev->pm);
7456c92544dSBjoern A. Zeeb }
7466c92544dSBjoern A. Zeeb
mt7615_tx(struct ieee80211_hw * hw,struct ieee80211_tx_control * control,struct sk_buff * skb)7476c92544dSBjoern A. Zeeb static void mt7615_tx(struct ieee80211_hw *hw,
7486c92544dSBjoern A. Zeeb struct ieee80211_tx_control *control,
7496c92544dSBjoern A. Zeeb struct sk_buff *skb)
7506c92544dSBjoern A. Zeeb {
7516c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
7526c92544dSBjoern A. Zeeb struct mt76_phy *mphy = hw->priv;
7536c92544dSBjoern A. Zeeb struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
7546c92544dSBjoern A. Zeeb struct ieee80211_vif *vif = info->control.vif;
7556c92544dSBjoern A. Zeeb struct mt76_wcid *wcid = &dev->mt76.global_wcid;
7566c92544dSBjoern A. Zeeb struct mt7615_sta *msta = NULL;
7576c92544dSBjoern A. Zeeb int qid;
7586c92544dSBjoern A. Zeeb
7596c92544dSBjoern A. Zeeb if (control->sta) {
7606c92544dSBjoern A. Zeeb msta = (struct mt7615_sta *)control->sta->drv_priv;
7616c92544dSBjoern A. Zeeb wcid = &msta->wcid;
7626c92544dSBjoern A. Zeeb }
7636c92544dSBjoern A. Zeeb
7646c92544dSBjoern A. Zeeb if (vif && !control->sta) {
7656c92544dSBjoern A. Zeeb struct mt7615_vif *mvif;
7666c92544dSBjoern A. Zeeb
7676c92544dSBjoern A. Zeeb mvif = (struct mt7615_vif *)vif->drv_priv;
7686c92544dSBjoern A. Zeeb msta = &mvif->sta;
7696c92544dSBjoern A. Zeeb wcid = &msta->wcid;
7706c92544dSBjoern A. Zeeb }
7716c92544dSBjoern A. Zeeb
7726c92544dSBjoern A. Zeeb if (mt76_connac_pm_ref(mphy, &dev->pm)) {
7736c92544dSBjoern A. Zeeb mt76_tx(mphy, control->sta, wcid, skb);
7746c92544dSBjoern A. Zeeb mt76_connac_pm_unref(mphy, &dev->pm);
7756c92544dSBjoern A. Zeeb return;
7766c92544dSBjoern A. Zeeb }
7776c92544dSBjoern A. Zeeb
7786c92544dSBjoern A. Zeeb qid = skb_get_queue_mapping(skb);
7796c92544dSBjoern A. Zeeb if (qid >= MT_TXQ_PSD) {
7806c92544dSBjoern A. Zeeb qid = IEEE80211_AC_BE;
7816c92544dSBjoern A. Zeeb skb_set_queue_mapping(skb, qid);
7826c92544dSBjoern A. Zeeb }
7836c92544dSBjoern A. Zeeb
7846c92544dSBjoern A. Zeeb mt76_connac_pm_queue_skb(hw, &dev->pm, wcid, skb);
7856c92544dSBjoern A. Zeeb }
7866c92544dSBjoern A. Zeeb
mt7615_set_rts_threshold(struct ieee80211_hw * hw,u32 val)7876c92544dSBjoern A. Zeeb static int mt7615_set_rts_threshold(struct ieee80211_hw *hw, u32 val)
7886c92544dSBjoern A. Zeeb {
7896c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
7906c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
7916c92544dSBjoern A. Zeeb int err, band = phy != &dev->phy;
7926c92544dSBjoern A. Zeeb
7936c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
7946c92544dSBjoern A. Zeeb err = mt76_connac_mcu_set_rts_thresh(&dev->mt76, val, band);
7956c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
7966c92544dSBjoern A. Zeeb
7976c92544dSBjoern A. Zeeb return err;
7986c92544dSBjoern A. Zeeb }
7996c92544dSBjoern A. Zeeb
8006c92544dSBjoern A. Zeeb static int
mt7615_ampdu_action(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_ampdu_params * params)8016c92544dSBjoern A. Zeeb mt7615_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
8026c92544dSBjoern A. Zeeb struct ieee80211_ampdu_params *params)
8036c92544dSBjoern A. Zeeb {
8046c92544dSBjoern A. Zeeb enum ieee80211_ampdu_mlme_action action = params->action;
8056c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
8066c92544dSBjoern A. Zeeb struct ieee80211_sta *sta = params->sta;
8076c92544dSBjoern A. Zeeb struct ieee80211_txq *txq = sta->txq[params->tid];
8086c92544dSBjoern A. Zeeb struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv;
8096c92544dSBjoern A. Zeeb u16 tid = params->tid;
8106c92544dSBjoern A. Zeeb u16 ssn = params->ssn;
8116c92544dSBjoern A. Zeeb struct mt76_txq *mtxq;
8126c92544dSBjoern A. Zeeb int ret = 0;
8136c92544dSBjoern A. Zeeb
8146c92544dSBjoern A. Zeeb if (!txq)
8156c92544dSBjoern A. Zeeb return -EINVAL;
8166c92544dSBjoern A. Zeeb
8176c92544dSBjoern A. Zeeb mtxq = (struct mt76_txq *)txq->drv_priv;
8186c92544dSBjoern A. Zeeb
8196c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
8206c92544dSBjoern A. Zeeb
8216c92544dSBjoern A. Zeeb switch (action) {
8226c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_RX_START:
8236c92544dSBjoern A. Zeeb mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, ssn,
8246c92544dSBjoern A. Zeeb params->buf_size);
8256c92544dSBjoern A. Zeeb ret = mt7615_mcu_add_rx_ba(dev, params, true);
8266c92544dSBjoern A. Zeeb break;
8276c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_RX_STOP:
8286c92544dSBjoern A. Zeeb mt76_rx_aggr_stop(&dev->mt76, &msta->wcid, tid);
8296c92544dSBjoern A. Zeeb ret = mt7615_mcu_add_rx_ba(dev, params, false);
8306c92544dSBjoern A. Zeeb break;
8316c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_OPERATIONAL:
8326c92544dSBjoern A. Zeeb mtxq->aggr = true;
8336c92544dSBjoern A. Zeeb mtxq->send_bar = false;
8346c92544dSBjoern A. Zeeb ret = mt7615_mcu_add_tx_ba(dev, params, true);
8356c92544dSBjoern A. Zeeb ssn = mt7615_mac_get_sta_tid_sn(dev, msta->wcid.idx, tid);
8366c92544dSBjoern A. Zeeb ieee80211_send_bar(vif, sta->addr, tid,
8376c92544dSBjoern A. Zeeb IEEE80211_SN_TO_SEQ(ssn));
8386c92544dSBjoern A. Zeeb break;
8396c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_STOP_FLUSH:
8406c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
8416c92544dSBjoern A. Zeeb mtxq->aggr = false;
8426c92544dSBjoern A. Zeeb ret = mt7615_mcu_add_tx_ba(dev, params, false);
8436c92544dSBjoern A. Zeeb break;
8446c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_START:
8456c92544dSBjoern A. Zeeb ssn = mt7615_mac_get_sta_tid_sn(dev, msta->wcid.idx, tid);
8466c92544dSBjoern A. Zeeb params->ssn = ssn;
8476c92544dSBjoern A. Zeeb ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;
8486c92544dSBjoern A. Zeeb break;
8496c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_STOP_CONT:
8506c92544dSBjoern A. Zeeb mtxq->aggr = false;
8516c92544dSBjoern A. Zeeb ret = mt7615_mcu_add_tx_ba(dev, params, false);
8526c92544dSBjoern A. Zeeb ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
8536c92544dSBjoern A. Zeeb break;
8546c92544dSBjoern A. Zeeb }
8556c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
8566c92544dSBjoern A. Zeeb
8576c92544dSBjoern A. Zeeb return ret;
8586c92544dSBjoern A. Zeeb }
8596c92544dSBjoern A. Zeeb
8606c92544dSBjoern A. Zeeb static int
mt7615_sta_add(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)8616c92544dSBjoern A. Zeeb mt7615_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
8626c92544dSBjoern A. Zeeb struct ieee80211_sta *sta)
8636c92544dSBjoern A. Zeeb {
8646c92544dSBjoern A. Zeeb return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NOTEXIST,
8656c92544dSBjoern A. Zeeb IEEE80211_STA_NONE);
8666c92544dSBjoern A. Zeeb }
8676c92544dSBjoern A. Zeeb
8686c92544dSBjoern A. Zeeb static int
mt7615_sta_remove(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)8696c92544dSBjoern A. Zeeb mt7615_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
8706c92544dSBjoern A. Zeeb struct ieee80211_sta *sta)
8716c92544dSBjoern A. Zeeb {
8726c92544dSBjoern A. Zeeb return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NONE,
8736c92544dSBjoern A. Zeeb IEEE80211_STA_NOTEXIST);
8746c92544dSBjoern A. Zeeb }
8756c92544dSBjoern A. Zeeb
8766c92544dSBjoern A. Zeeb static int
mt7615_get_stats(struct ieee80211_hw * hw,struct ieee80211_low_level_stats * stats)8776c92544dSBjoern A. Zeeb mt7615_get_stats(struct ieee80211_hw *hw,
8786c92544dSBjoern A. Zeeb struct ieee80211_low_level_stats *stats)
8796c92544dSBjoern A. Zeeb {
8806c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
8816c92544dSBjoern A. Zeeb struct mib_stats *mib = &phy->mib;
8826c92544dSBjoern A. Zeeb
8836c92544dSBjoern A. Zeeb mt7615_mutex_acquire(phy->dev);
8846c92544dSBjoern A. Zeeb
8856c92544dSBjoern A. Zeeb stats->dot11RTSSuccessCount = mib->rts_cnt;
8866c92544dSBjoern A. Zeeb stats->dot11RTSFailureCount = mib->rts_retries_cnt;
8876c92544dSBjoern A. Zeeb stats->dot11FCSErrorCount = mib->fcs_err_cnt;
8886c92544dSBjoern A. Zeeb stats->dot11ACKFailureCount = mib->ack_fail_cnt;
8896c92544dSBjoern A. Zeeb
8906c92544dSBjoern A. Zeeb mt7615_mutex_release(phy->dev);
8916c92544dSBjoern A. Zeeb
8926c92544dSBjoern A. Zeeb return 0;
8936c92544dSBjoern A. Zeeb }
8946c92544dSBjoern A. Zeeb
8956c92544dSBjoern A. Zeeb static u64
mt7615_get_tsf(struct ieee80211_hw * hw,struct ieee80211_vif * vif)8966c92544dSBjoern A. Zeeb mt7615_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
8976c92544dSBjoern A. Zeeb {
8986c92544dSBjoern A. Zeeb struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
8996c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
9006c92544dSBjoern A. Zeeb union {
9016c92544dSBjoern A. Zeeb u64 t64;
9026c92544dSBjoern A. Zeeb u32 t32[2];
9036c92544dSBjoern A. Zeeb } tsf;
9046c92544dSBjoern A. Zeeb u16 idx = mvif->mt76.omac_idx;
9056c92544dSBjoern A. Zeeb u32 reg;
9066c92544dSBjoern A. Zeeb
9076c92544dSBjoern A. Zeeb idx = idx > HW_BSSID_MAX ? HW_BSSID_0 : idx;
9086c92544dSBjoern A. Zeeb reg = idx > 1 ? MT_LPON_TCR2(idx): MT_LPON_TCR0(idx);
9096c92544dSBjoern A. Zeeb
9106c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
9116c92544dSBjoern A. Zeeb
9126c92544dSBjoern A. Zeeb /* TSF read */
9136c92544dSBjoern A. Zeeb mt76_rmw(dev, reg, MT_LPON_TCR_MODE, MT_LPON_TCR_READ);
9146c92544dSBjoern A. Zeeb tsf.t32[0] = mt76_rr(dev, MT_LPON_UTTR0);
9156c92544dSBjoern A. Zeeb tsf.t32[1] = mt76_rr(dev, MT_LPON_UTTR1);
9166c92544dSBjoern A. Zeeb
9176c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
9186c92544dSBjoern A. Zeeb
9196c92544dSBjoern A. Zeeb return tsf.t64;
9206c92544dSBjoern A. Zeeb }
9216c92544dSBjoern A. Zeeb
9226c92544dSBjoern A. Zeeb static void
mt7615_set_tsf(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u64 timestamp)9236c92544dSBjoern A. Zeeb mt7615_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
9246c92544dSBjoern A. Zeeb u64 timestamp)
9256c92544dSBjoern A. Zeeb {
9266c92544dSBjoern A. Zeeb struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
9276c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
9286c92544dSBjoern A. Zeeb union {
9296c92544dSBjoern A. Zeeb u64 t64;
9306c92544dSBjoern A. Zeeb u32 t32[2];
9316c92544dSBjoern A. Zeeb } tsf = { .t64 = timestamp, };
9326c92544dSBjoern A. Zeeb u16 idx = mvif->mt76.omac_idx;
9336c92544dSBjoern A. Zeeb u32 reg;
9346c92544dSBjoern A. Zeeb
9356c92544dSBjoern A. Zeeb idx = idx > HW_BSSID_MAX ? HW_BSSID_0 : idx;
9366c92544dSBjoern A. Zeeb reg = idx > 1 ? MT_LPON_TCR2(idx): MT_LPON_TCR0(idx);
9376c92544dSBjoern A. Zeeb
9386c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
9396c92544dSBjoern A. Zeeb
9406c92544dSBjoern A. Zeeb mt76_wr(dev, MT_LPON_UTTR0, tsf.t32[0]);
9416c92544dSBjoern A. Zeeb mt76_wr(dev, MT_LPON_UTTR1, tsf.t32[1]);
9426c92544dSBjoern A. Zeeb /* TSF software overwrite */
9436c92544dSBjoern A. Zeeb mt76_rmw(dev, reg, MT_LPON_TCR_MODE, MT_LPON_TCR_WRITE);
9446c92544dSBjoern A. Zeeb
9456c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
9466c92544dSBjoern A. Zeeb }
9476c92544dSBjoern A. Zeeb
9486c92544dSBjoern A. Zeeb static void
mt7615_offset_tsf(struct ieee80211_hw * hw,struct ieee80211_vif * vif,s64 timestamp)9496c92544dSBjoern A. Zeeb mt7615_offset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
9506c92544dSBjoern A. Zeeb s64 timestamp)
9516c92544dSBjoern A. Zeeb {
9526c92544dSBjoern A. Zeeb struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
9536c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
9546c92544dSBjoern A. Zeeb union {
9556c92544dSBjoern A. Zeeb u64 t64;
9566c92544dSBjoern A. Zeeb u32 t32[2];
9576c92544dSBjoern A. Zeeb } tsf = { .t64 = timestamp, };
9586c92544dSBjoern A. Zeeb u16 idx = mvif->mt76.omac_idx;
9596c92544dSBjoern A. Zeeb u32 reg;
9606c92544dSBjoern A. Zeeb
9616c92544dSBjoern A. Zeeb idx = idx > HW_BSSID_MAX ? HW_BSSID_0 : idx;
9626c92544dSBjoern A. Zeeb reg = idx > 1 ? MT_LPON_TCR2(idx): MT_LPON_TCR0(idx);
9636c92544dSBjoern A. Zeeb
9646c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
9656c92544dSBjoern A. Zeeb
9666c92544dSBjoern A. Zeeb mt76_wr(dev, MT_LPON_UTTR0, tsf.t32[0]);
9676c92544dSBjoern A. Zeeb mt76_wr(dev, MT_LPON_UTTR1, tsf.t32[1]);
9686c92544dSBjoern A. Zeeb /* TSF software adjust*/
9696c92544dSBjoern A. Zeeb mt76_rmw(dev, reg, MT_LPON_TCR_MODE, MT_LPON_TCR_ADJUST);
9706c92544dSBjoern A. Zeeb
9716c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
9726c92544dSBjoern A. Zeeb }
9736c92544dSBjoern A. Zeeb
9746c92544dSBjoern A. Zeeb static void
mt7615_set_coverage_class(struct ieee80211_hw * hw,s16 coverage_class)9756c92544dSBjoern A. Zeeb mt7615_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class)
9766c92544dSBjoern A. Zeeb {
9776c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
9786c92544dSBjoern A. Zeeb struct mt7615_dev *dev = phy->dev;
9796c92544dSBjoern A. Zeeb
9806c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
9816c92544dSBjoern A. Zeeb phy->coverage_class = max_t(s16, coverage_class, 0);
9826c92544dSBjoern A. Zeeb mt7615_mac_set_timing(phy);
9836c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
9846c92544dSBjoern A. Zeeb }
9856c92544dSBjoern A. Zeeb
9866c92544dSBjoern A. Zeeb static int
mt7615_set_antenna(struct ieee80211_hw * hw,u32 tx_ant,u32 rx_ant)9876c92544dSBjoern A. Zeeb mt7615_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
9886c92544dSBjoern A. Zeeb {
9896c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
9906c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
9916c92544dSBjoern A. Zeeb int max_nss = hweight8(hw->wiphy->available_antennas_tx);
9926c92544dSBjoern A. Zeeb bool ext_phy = phy != &dev->phy;
9936c92544dSBjoern A. Zeeb
9946c92544dSBjoern A. Zeeb if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss)
9956c92544dSBjoern A. Zeeb return -EINVAL;
9966c92544dSBjoern A. Zeeb
9976c92544dSBjoern A. Zeeb if ((BIT(hweight8(tx_ant)) - 1) != tx_ant)
9986c92544dSBjoern A. Zeeb tx_ant = BIT(ffs(tx_ant) - 1) - 1;
9996c92544dSBjoern A. Zeeb
10006c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
10016c92544dSBjoern A. Zeeb
10026c92544dSBjoern A. Zeeb phy->mt76->antenna_mask = tx_ant;
10036c92544dSBjoern A. Zeeb if (ext_phy) {
10046c92544dSBjoern A. Zeeb if (dev->chainmask == 0xf)
10056c92544dSBjoern A. Zeeb tx_ant <<= 2;
10066c92544dSBjoern A. Zeeb else
10076c92544dSBjoern A. Zeeb tx_ant <<= 1;
10086c92544dSBjoern A. Zeeb }
10096c92544dSBjoern A. Zeeb phy->mt76->chainmask = tx_ant;
10106c92544dSBjoern A. Zeeb
10116c92544dSBjoern A. Zeeb mt76_set_stream_caps(phy->mt76, true);
10126c92544dSBjoern A. Zeeb
10136c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
10146c92544dSBjoern A. Zeeb
10156c92544dSBjoern A. Zeeb return 0;
10166c92544dSBjoern A. Zeeb }
10176c92544dSBjoern A. Zeeb
mt7615_roc_iter(void * priv,u8 * mac,struct ieee80211_vif * vif)10186c92544dSBjoern A. Zeeb static void mt7615_roc_iter(void *priv, u8 *mac,
10196c92544dSBjoern A. Zeeb struct ieee80211_vif *vif)
10206c92544dSBjoern A. Zeeb {
10216c92544dSBjoern A. Zeeb struct mt7615_phy *phy = priv;
10226c92544dSBjoern A. Zeeb
10236c92544dSBjoern A. Zeeb mt7615_mcu_set_roc(phy, vif, NULL, 0);
10246c92544dSBjoern A. Zeeb }
10256c92544dSBjoern A. Zeeb
mt7615_roc_work(struct work_struct * work)10266c92544dSBjoern A. Zeeb void mt7615_roc_work(struct work_struct *work)
10276c92544dSBjoern A. Zeeb {
10286c92544dSBjoern A. Zeeb struct mt7615_phy *phy;
10296c92544dSBjoern A. Zeeb
10306c92544dSBjoern A. Zeeb phy = (struct mt7615_phy *)container_of(work, struct mt7615_phy,
10316c92544dSBjoern A. Zeeb roc_work);
10326c92544dSBjoern A. Zeeb
10336c92544dSBjoern A. Zeeb if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
10346c92544dSBjoern A. Zeeb return;
10356c92544dSBjoern A. Zeeb
10366c92544dSBjoern A. Zeeb mt7615_mutex_acquire(phy->dev);
10376c92544dSBjoern A. Zeeb ieee80211_iterate_active_interfaces(phy->mt76->hw,
10386c92544dSBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL,
10396c92544dSBjoern A. Zeeb mt7615_roc_iter, phy);
10406c92544dSBjoern A. Zeeb mt7615_mutex_release(phy->dev);
10416c92544dSBjoern A. Zeeb ieee80211_remain_on_channel_expired(phy->mt76->hw);
10426c92544dSBjoern A. Zeeb }
10436c92544dSBjoern A. Zeeb
mt7615_roc_timer(struct timer_list * timer)10446c92544dSBjoern A. Zeeb void mt7615_roc_timer(struct timer_list *timer)
10456c92544dSBjoern A. Zeeb {
10466c92544dSBjoern A. Zeeb struct mt7615_phy *phy = from_timer(phy, timer, roc_timer);
10476c92544dSBjoern A. Zeeb
10486c92544dSBjoern A. Zeeb ieee80211_queue_work(phy->mt76->hw, &phy->roc_work);
10496c92544dSBjoern A. Zeeb }
10506c92544dSBjoern A. Zeeb
mt7615_scan_work(struct work_struct * work)10516c92544dSBjoern A. Zeeb void mt7615_scan_work(struct work_struct *work)
10526c92544dSBjoern A. Zeeb {
10536c92544dSBjoern A. Zeeb struct mt7615_phy *phy;
10546c92544dSBjoern A. Zeeb
10556c92544dSBjoern A. Zeeb phy = (struct mt7615_phy *)container_of(work, struct mt7615_phy,
10566c92544dSBjoern A. Zeeb scan_work.work);
10576c92544dSBjoern A. Zeeb
10586c92544dSBjoern A. Zeeb while (true) {
10596c92544dSBjoern A. Zeeb struct mt7615_mcu_rxd *rxd;
10606c92544dSBjoern A. Zeeb struct sk_buff *skb;
10616c92544dSBjoern A. Zeeb
10626c92544dSBjoern A. Zeeb spin_lock_bh(&phy->dev->mt76.lock);
10636c92544dSBjoern A. Zeeb skb = __skb_dequeue(&phy->scan_event_list);
10646c92544dSBjoern A. Zeeb spin_unlock_bh(&phy->dev->mt76.lock);
10656c92544dSBjoern A. Zeeb
10666c92544dSBjoern A. Zeeb if (!skb)
10676c92544dSBjoern A. Zeeb break;
10686c92544dSBjoern A. Zeeb
10696c92544dSBjoern A. Zeeb rxd = (struct mt7615_mcu_rxd *)skb->data;
10706c92544dSBjoern A. Zeeb if (rxd->eid == MCU_EVENT_SCHED_SCAN_DONE) {
10716c92544dSBjoern A. Zeeb ieee80211_sched_scan_results(phy->mt76->hw);
10726c92544dSBjoern A. Zeeb } else if (test_and_clear_bit(MT76_HW_SCANNING,
10736c92544dSBjoern A. Zeeb &phy->mt76->state)) {
10746c92544dSBjoern A. Zeeb struct cfg80211_scan_info info = {
10756c92544dSBjoern A. Zeeb .aborted = false,
10766c92544dSBjoern A. Zeeb };
10776c92544dSBjoern A. Zeeb
10786c92544dSBjoern A. Zeeb ieee80211_scan_completed(phy->mt76->hw, &info);
10796c92544dSBjoern A. Zeeb }
10806c92544dSBjoern A. Zeeb dev_kfree_skb(skb);
10816c92544dSBjoern A. Zeeb }
10826c92544dSBjoern A. Zeeb }
10836c92544dSBjoern A. Zeeb
10846c92544dSBjoern A. Zeeb static int
mt7615_hw_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_scan_request * req)10856c92544dSBjoern A. Zeeb mt7615_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
10866c92544dSBjoern A. Zeeb struct ieee80211_scan_request *req)
10876c92544dSBjoern A. Zeeb {
10886c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
10896c92544dSBjoern A. Zeeb struct mt76_phy *mphy = hw->priv;
10906c92544dSBjoern A. Zeeb int err;
10916c92544dSBjoern A. Zeeb
10926c92544dSBjoern A. Zeeb /* fall-back to sw-scan */
10936c92544dSBjoern A. Zeeb if (!mt7615_firmware_offload(dev))
10946c92544dSBjoern A. Zeeb return 1;
10956c92544dSBjoern A. Zeeb
10966c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
10976c92544dSBjoern A. Zeeb err = mt76_connac_mcu_hw_scan(mphy, vif, req);
10986c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
10996c92544dSBjoern A. Zeeb
11006c92544dSBjoern A. Zeeb return err;
11016c92544dSBjoern A. Zeeb }
11026c92544dSBjoern A. Zeeb
11036c92544dSBjoern A. Zeeb static void
mt7615_cancel_hw_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif)11046c92544dSBjoern A. Zeeb mt7615_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
11056c92544dSBjoern A. Zeeb {
11066c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
11076c92544dSBjoern A. Zeeb struct mt76_phy *mphy = hw->priv;
11086c92544dSBjoern A. Zeeb
11096c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
11106c92544dSBjoern A. Zeeb mt76_connac_mcu_cancel_hw_scan(mphy, vif);
11116c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
11126c92544dSBjoern A. Zeeb }
11136c92544dSBjoern A. Zeeb
11146c92544dSBjoern A. Zeeb static int
mt7615_start_sched_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct cfg80211_sched_scan_request * req,struct ieee80211_scan_ies * ies)11156c92544dSBjoern A. Zeeb mt7615_start_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
11166c92544dSBjoern A. Zeeb struct cfg80211_sched_scan_request *req,
11176c92544dSBjoern A. Zeeb struct ieee80211_scan_ies *ies)
11186c92544dSBjoern A. Zeeb {
11196c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
11206c92544dSBjoern A. Zeeb struct mt76_phy *mphy = hw->priv;
11216c92544dSBjoern A. Zeeb int err;
11226c92544dSBjoern A. Zeeb
11236c92544dSBjoern A. Zeeb if (!mt7615_firmware_offload(dev))
11246c92544dSBjoern A. Zeeb return -EOPNOTSUPP;
11256c92544dSBjoern A. Zeeb
11266c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
11276c92544dSBjoern A. Zeeb
11286c92544dSBjoern A. Zeeb err = mt76_connac_mcu_sched_scan_req(mphy, vif, req);
11296c92544dSBjoern A. Zeeb if (err < 0)
11306c92544dSBjoern A. Zeeb goto out;
11316c92544dSBjoern A. Zeeb
11326c92544dSBjoern A. Zeeb err = mt76_connac_mcu_sched_scan_enable(mphy, vif, true);
11336c92544dSBjoern A. Zeeb out:
11346c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
11356c92544dSBjoern A. Zeeb
11366c92544dSBjoern A. Zeeb return err;
11376c92544dSBjoern A. Zeeb }
11386c92544dSBjoern A. Zeeb
11396c92544dSBjoern A. Zeeb static int
mt7615_stop_sched_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif)11406c92544dSBjoern A. Zeeb mt7615_stop_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
11416c92544dSBjoern A. Zeeb {
11426c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
11436c92544dSBjoern A. Zeeb struct mt76_phy *mphy = hw->priv;
11446c92544dSBjoern A. Zeeb int err;
11456c92544dSBjoern A. Zeeb
11466c92544dSBjoern A. Zeeb if (!mt7615_firmware_offload(dev))
11476c92544dSBjoern A. Zeeb return -EOPNOTSUPP;
11486c92544dSBjoern A. Zeeb
11496c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
11506c92544dSBjoern A. Zeeb err = mt76_connac_mcu_sched_scan_enable(mphy, vif, false);
11516c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
11526c92544dSBjoern A. Zeeb
11536c92544dSBjoern A. Zeeb return err;
11546c92544dSBjoern A. Zeeb }
11556c92544dSBjoern A. Zeeb
mt7615_remain_on_channel(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_channel * chan,int duration,enum ieee80211_roc_type type)11566c92544dSBjoern A. Zeeb static int mt7615_remain_on_channel(struct ieee80211_hw *hw,
11576c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
11586c92544dSBjoern A. Zeeb struct ieee80211_channel *chan,
11596c92544dSBjoern A. Zeeb int duration,
11606c92544dSBjoern A. Zeeb enum ieee80211_roc_type type)
11616c92544dSBjoern A. Zeeb {
11626c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
11636c92544dSBjoern A. Zeeb int err;
11646c92544dSBjoern A. Zeeb
11656c92544dSBjoern A. Zeeb if (test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state))
11666c92544dSBjoern A. Zeeb return 0;
11676c92544dSBjoern A. Zeeb
11686c92544dSBjoern A. Zeeb mt7615_mutex_acquire(phy->dev);
11696c92544dSBjoern A. Zeeb
11706c92544dSBjoern A. Zeeb err = mt7615_mcu_set_roc(phy, vif, chan, duration);
11716c92544dSBjoern A. Zeeb if (err < 0) {
11726c92544dSBjoern A. Zeeb clear_bit(MT76_STATE_ROC, &phy->mt76->state);
11736c92544dSBjoern A. Zeeb goto out;
11746c92544dSBjoern A. Zeeb }
11756c92544dSBjoern A. Zeeb
11766c92544dSBjoern A. Zeeb if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, HZ)) {
11776c92544dSBjoern A. Zeeb mt7615_mcu_set_roc(phy, vif, NULL, 0);
11786c92544dSBjoern A. Zeeb clear_bit(MT76_STATE_ROC, &phy->mt76->state);
11796c92544dSBjoern A. Zeeb err = -ETIMEDOUT;
11806c92544dSBjoern A. Zeeb }
11816c92544dSBjoern A. Zeeb
11826c92544dSBjoern A. Zeeb out:
11836c92544dSBjoern A. Zeeb mt7615_mutex_release(phy->dev);
11846c92544dSBjoern A. Zeeb
11856c92544dSBjoern A. Zeeb return err;
11866c92544dSBjoern A. Zeeb }
11876c92544dSBjoern A. Zeeb
mt7615_cancel_remain_on_channel(struct ieee80211_hw * hw,struct ieee80211_vif * vif)11886c92544dSBjoern A. Zeeb static int mt7615_cancel_remain_on_channel(struct ieee80211_hw *hw,
11896c92544dSBjoern A. Zeeb struct ieee80211_vif *vif)
11906c92544dSBjoern A. Zeeb {
11916c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
11926c92544dSBjoern A. Zeeb int err;
11936c92544dSBjoern A. Zeeb
11946c92544dSBjoern A. Zeeb if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
11956c92544dSBjoern A. Zeeb return 0;
11966c92544dSBjoern A. Zeeb
11976c92544dSBjoern A. Zeeb del_timer_sync(&phy->roc_timer);
11986c92544dSBjoern A. Zeeb cancel_work_sync(&phy->roc_work);
11996c92544dSBjoern A. Zeeb
12006c92544dSBjoern A. Zeeb mt7615_mutex_acquire(phy->dev);
12016c92544dSBjoern A. Zeeb err = mt7615_mcu_set_roc(phy, vif, NULL, 0);
12026c92544dSBjoern A. Zeeb mt7615_mutex_release(phy->dev);
12036c92544dSBjoern A. Zeeb
12046c92544dSBjoern A. Zeeb return err;
12056c92544dSBjoern A. Zeeb }
12066c92544dSBjoern A. Zeeb
mt7615_sta_set_decap_offload(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta,bool enabled)12076c92544dSBjoern A. Zeeb static void mt7615_sta_set_decap_offload(struct ieee80211_hw *hw,
12086c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
12096c92544dSBjoern A. Zeeb struct ieee80211_sta *sta,
12106c92544dSBjoern A. Zeeb bool enabled)
12116c92544dSBjoern A. Zeeb {
12126c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
12136c92544dSBjoern A. Zeeb struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv;
12146c92544dSBjoern A. Zeeb
12156c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
12166c92544dSBjoern A. Zeeb
12176c92544dSBjoern A. Zeeb if (enabled)
12186c92544dSBjoern A. Zeeb set_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags);
12196c92544dSBjoern A. Zeeb else
12206c92544dSBjoern A. Zeeb clear_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags);
12216c92544dSBjoern A. Zeeb
12226c92544dSBjoern A. Zeeb mt7615_mcu_set_sta_decap_offload(dev, vif, sta);
12236c92544dSBjoern A. Zeeb
12246c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
12256c92544dSBjoern A. Zeeb }
12266c92544dSBjoern A. Zeeb
12276c92544dSBjoern A. Zeeb #ifdef CONFIG_PM
mt7615_suspend(struct ieee80211_hw * hw,struct cfg80211_wowlan * wowlan)12286c92544dSBjoern A. Zeeb static int mt7615_suspend(struct ieee80211_hw *hw,
12296c92544dSBjoern A. Zeeb struct cfg80211_wowlan *wowlan)
12306c92544dSBjoern A. Zeeb {
12316c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
12326c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
12336c92544dSBjoern A. Zeeb int err = 0;
12346c92544dSBjoern A. Zeeb
12356c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&dev->pm.ps_work);
12366c92544dSBjoern A. Zeeb mt76_connac_free_pending_tx_skbs(&dev->pm, NULL);
12376c92544dSBjoern A. Zeeb
12386c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
12396c92544dSBjoern A. Zeeb
12406c92544dSBjoern A. Zeeb clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
12416c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&phy->scan_work);
12426c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&phy->mt76->mac_work);
12436c92544dSBjoern A. Zeeb
12446c92544dSBjoern A. Zeeb set_bit(MT76_STATE_SUSPEND, &phy->mt76->state);
12456c92544dSBjoern A. Zeeb ieee80211_iterate_active_interfaces(hw,
12466c92544dSBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL,
12476c92544dSBjoern A. Zeeb mt76_connac_mcu_set_suspend_iter,
12486c92544dSBjoern A. Zeeb phy->mt76);
12496c92544dSBjoern A. Zeeb
12506c92544dSBjoern A. Zeeb if (!mt7615_dev_running(dev))
1251*8ba4d145SBjoern A. Zeeb err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, true, true);
12526c92544dSBjoern A. Zeeb
12536c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
12546c92544dSBjoern A. Zeeb
12556c92544dSBjoern A. Zeeb return err;
12566c92544dSBjoern A. Zeeb }
12576c92544dSBjoern A. Zeeb
mt7615_resume(struct ieee80211_hw * hw)12586c92544dSBjoern A. Zeeb static int mt7615_resume(struct ieee80211_hw *hw)
12596c92544dSBjoern A. Zeeb {
12606c92544dSBjoern A. Zeeb struct mt7615_phy *phy = mt7615_hw_phy(hw);
12616c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
12626c92544dSBjoern A. Zeeb unsigned long timeout;
12636c92544dSBjoern A. Zeeb bool running;
12646c92544dSBjoern A. Zeeb
12656c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
12666c92544dSBjoern A. Zeeb
12676c92544dSBjoern A. Zeeb running = mt7615_dev_running(dev);
12686c92544dSBjoern A. Zeeb set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
12696c92544dSBjoern A. Zeeb
12706c92544dSBjoern A. Zeeb if (!running) {
12716c92544dSBjoern A. Zeeb int err;
12726c92544dSBjoern A. Zeeb
1273*8ba4d145SBjoern A. Zeeb err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, false, true);
12746c92544dSBjoern A. Zeeb if (err < 0) {
12756c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
12766c92544dSBjoern A. Zeeb return err;
12776c92544dSBjoern A. Zeeb }
12786c92544dSBjoern A. Zeeb }
12796c92544dSBjoern A. Zeeb
12806c92544dSBjoern A. Zeeb clear_bit(MT76_STATE_SUSPEND, &phy->mt76->state);
12816c92544dSBjoern A. Zeeb ieee80211_iterate_active_interfaces(hw,
12826c92544dSBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL,
12836c92544dSBjoern A. Zeeb mt76_connac_mcu_set_suspend_iter,
12846c92544dSBjoern A. Zeeb phy->mt76);
12856c92544dSBjoern A. Zeeb
12866c92544dSBjoern A. Zeeb timeout = mt7615_get_macwork_timeout(dev);
12876c92544dSBjoern A. Zeeb ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work, timeout);
12886c92544dSBjoern A. Zeeb
12896c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
12906c92544dSBjoern A. Zeeb
12916c92544dSBjoern A. Zeeb return 0;
12926c92544dSBjoern A. Zeeb }
12936c92544dSBjoern A. Zeeb
mt7615_set_wakeup(struct ieee80211_hw * hw,bool enabled)12946c92544dSBjoern A. Zeeb static void mt7615_set_wakeup(struct ieee80211_hw *hw, bool enabled)
12956c92544dSBjoern A. Zeeb {
12966c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
12976c92544dSBjoern A. Zeeb struct mt76_dev *mdev = &dev->mt76;
12986c92544dSBjoern A. Zeeb
12996c92544dSBjoern A. Zeeb device_set_wakeup_enable(mdev->dev, enabled);
13006c92544dSBjoern A. Zeeb }
13016c92544dSBjoern A. Zeeb
mt7615_set_rekey_data(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct cfg80211_gtk_rekey_data * data)13026c92544dSBjoern A. Zeeb static void mt7615_set_rekey_data(struct ieee80211_hw *hw,
13036c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
13046c92544dSBjoern A. Zeeb struct cfg80211_gtk_rekey_data *data)
13056c92544dSBjoern A. Zeeb {
13066c92544dSBjoern A. Zeeb struct mt7615_dev *dev = mt7615_hw_dev(hw);
13076c92544dSBjoern A. Zeeb
13086c92544dSBjoern A. Zeeb mt7615_mutex_acquire(dev);
13096c92544dSBjoern A. Zeeb mt76_connac_mcu_update_gtk_rekey(hw, vif, data);
13106c92544dSBjoern A. Zeeb mt7615_mutex_release(dev);
13116c92544dSBjoern A. Zeeb }
13126c92544dSBjoern A. Zeeb #endif /* CONFIG_PM */
13136c92544dSBjoern A. Zeeb
13146c92544dSBjoern A. Zeeb const struct ieee80211_ops mt7615_ops = {
1315*8ba4d145SBjoern A. Zeeb .add_chanctx = ieee80211_emulate_add_chanctx,
1316*8ba4d145SBjoern A. Zeeb .remove_chanctx = ieee80211_emulate_remove_chanctx,
1317*8ba4d145SBjoern A. Zeeb .change_chanctx = ieee80211_emulate_change_chanctx,
1318*8ba4d145SBjoern A. Zeeb .switch_vif_chanctx = ieee80211_emulate_switch_vif_chanctx,
13196c92544dSBjoern A. Zeeb .tx = mt7615_tx,
13206c92544dSBjoern A. Zeeb .start = mt7615_start,
13216c92544dSBjoern A. Zeeb .stop = mt7615_stop,
13226c92544dSBjoern A. Zeeb .add_interface = mt7615_add_interface,
13236c92544dSBjoern A. Zeeb .remove_interface = mt7615_remove_interface,
13246c92544dSBjoern A. Zeeb .config = mt7615_config,
13256c92544dSBjoern A. Zeeb .conf_tx = mt7615_conf_tx,
13266c92544dSBjoern A. Zeeb .configure_filter = mt7615_configure_filter,
13276c92544dSBjoern A. Zeeb .bss_info_changed = mt7615_bss_info_changed,
13286c92544dSBjoern A. Zeeb .sta_add = mt7615_sta_add,
13296c92544dSBjoern A. Zeeb .sta_remove = mt7615_sta_remove,
13306c92544dSBjoern A. Zeeb .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
13316c92544dSBjoern A. Zeeb .set_key = mt7615_set_key,
13326c92544dSBjoern A. Zeeb .sta_set_decap_offload = mt7615_sta_set_decap_offload,
13336c92544dSBjoern A. Zeeb .ampdu_action = mt7615_ampdu_action,
13346c92544dSBjoern A. Zeeb .set_rts_threshold = mt7615_set_rts_threshold,
13356c92544dSBjoern A. Zeeb .wake_tx_queue = mt76_wake_tx_queue,
13366c92544dSBjoern A. Zeeb .sta_rate_tbl_update = mt7615_sta_rate_tbl_update,
13376c92544dSBjoern A. Zeeb .sw_scan_start = mt76_sw_scan,
13386c92544dSBjoern A. Zeeb .sw_scan_complete = mt76_sw_scan_complete,
13396c92544dSBjoern A. Zeeb .release_buffered_frames = mt76_release_buffered_frames,
13406c92544dSBjoern A. Zeeb .get_txpower = mt76_get_txpower,
13416c92544dSBjoern A. Zeeb .channel_switch_beacon = mt7615_channel_switch_beacon,
13426c92544dSBjoern A. Zeeb .get_stats = mt7615_get_stats,
13436c92544dSBjoern A. Zeeb .get_tsf = mt7615_get_tsf,
13446c92544dSBjoern A. Zeeb .set_tsf = mt7615_set_tsf,
13456c92544dSBjoern A. Zeeb .offset_tsf = mt7615_offset_tsf,
13466c92544dSBjoern A. Zeeb .get_survey = mt76_get_survey,
13476c92544dSBjoern A. Zeeb .get_antenna = mt76_get_antenna,
13486c92544dSBjoern A. Zeeb .set_antenna = mt7615_set_antenna,
13496c92544dSBjoern A. Zeeb .set_coverage_class = mt7615_set_coverage_class,
13506c92544dSBjoern A. Zeeb .hw_scan = mt7615_hw_scan,
13516c92544dSBjoern A. Zeeb .cancel_hw_scan = mt7615_cancel_hw_scan,
13526c92544dSBjoern A. Zeeb .sched_scan_start = mt7615_start_sched_scan,
13536c92544dSBjoern A. Zeeb .sched_scan_stop = mt7615_stop_sched_scan,
13546c92544dSBjoern A. Zeeb .remain_on_channel = mt7615_remain_on_channel,
13556c92544dSBjoern A. Zeeb .cancel_remain_on_channel = mt7615_cancel_remain_on_channel,
13566c92544dSBjoern A. Zeeb CFG80211_TESTMODE_CMD(mt76_testmode_cmd)
13576c92544dSBjoern A. Zeeb CFG80211_TESTMODE_DUMP(mt76_testmode_dump)
13586c92544dSBjoern A. Zeeb #ifdef CONFIG_PM
13596c92544dSBjoern A. Zeeb .suspend = mt7615_suspend,
13606c92544dSBjoern A. Zeeb .resume = mt7615_resume,
13616c92544dSBjoern A. Zeeb .set_wakeup = mt7615_set_wakeup,
13626c92544dSBjoern A. Zeeb .set_rekey_data = mt7615_set_rekey_data,
13636c92544dSBjoern A. Zeeb #endif /* CONFIG_PM */
13646c92544dSBjoern A. Zeeb .set_sar_specs = mt7615_set_sar_specs,
13656c92544dSBjoern A. Zeeb };
13666c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt7615_ops);
13676c92544dSBjoern A. Zeeb
1368*8ba4d145SBjoern A. Zeeb MODULE_DESCRIPTION("MediaTek MT7615E and MT7663E wireless driver");
13696c92544dSBjoern A. Zeeb MODULE_LICENSE("Dual BSD/GPL");
1370