16c92544dSBjoern A. Zeeb // SPDX-License-Identifier: ISC
26c92544dSBjoern A. Zeeb /*
36c92544dSBjoern A. Zeeb * Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
46c92544dSBjoern A. Zeeb */
56c92544dSBjoern A. Zeeb
66c92544dSBjoern A. Zeeb #include "mt76x2u.h"
76c92544dSBjoern A. Zeeb #include "../mt76x02_usb.h"
86c92544dSBjoern A. Zeeb
mt76x2u_start(struct ieee80211_hw * hw)96c92544dSBjoern A. Zeeb static int mt76x2u_start(struct ieee80211_hw *hw)
106c92544dSBjoern A. Zeeb {
116c92544dSBjoern A. Zeeb struct mt76x02_dev *dev = hw->priv;
126c92544dSBjoern A. Zeeb int ret;
136c92544dSBjoern A. Zeeb
146c92544dSBjoern A. Zeeb ret = mt76x02u_mac_start(dev);
156c92544dSBjoern A. Zeeb if (ret)
166c92544dSBjoern A. Zeeb return ret;
176c92544dSBjoern A. Zeeb
186c92544dSBjoern A. Zeeb ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work,
196c92544dSBjoern A. Zeeb MT_MAC_WORK_INTERVAL);
206c92544dSBjoern A. Zeeb set_bit(MT76_STATE_RUNNING, &dev->mphy.state);
216c92544dSBjoern A. Zeeb
226c92544dSBjoern A. Zeeb return 0;
236c92544dSBjoern A. Zeeb }
246c92544dSBjoern A. Zeeb
mt76x2u_stop(struct ieee80211_hw * hw,bool suspend)25*8ba4d145SBjoern A. Zeeb static void mt76x2u_stop(struct ieee80211_hw *hw, bool suspend)
266c92544dSBjoern A. Zeeb {
276c92544dSBjoern A. Zeeb struct mt76x02_dev *dev = hw->priv;
286c92544dSBjoern A. Zeeb
296c92544dSBjoern A. Zeeb clear_bit(MT76_STATE_RUNNING, &dev->mphy.state);
306c92544dSBjoern A. Zeeb mt76u_stop_tx(&dev->mt76);
316c92544dSBjoern A. Zeeb mt76x2u_stop_hw(dev);
326c92544dSBjoern A. Zeeb }
336c92544dSBjoern A. Zeeb
mt76x2u_set_channel(struct mt76_phy * mphy)34*8ba4d145SBjoern A. Zeeb int mt76x2u_set_channel(struct mt76_phy *mphy)
356c92544dSBjoern A. Zeeb {
36*8ba4d145SBjoern A. Zeeb struct mt76x02_dev *dev = container_of(mphy->dev, struct mt76x02_dev, mt76);
376c92544dSBjoern A. Zeeb int err;
386c92544dSBjoern A. Zeeb
396c92544dSBjoern A. Zeeb mt76x02_pre_tbtt_enable(dev, false);
406c92544dSBjoern A. Zeeb mt76x2_mac_stop(dev, false);
416c92544dSBjoern A. Zeeb
42*8ba4d145SBjoern A. Zeeb err = mt76x2u_phy_set_channel(dev, &mphy->chandef);
436c92544dSBjoern A. Zeeb
446c92544dSBjoern A. Zeeb mt76x02_mac_cc_reset(dev);
456c92544dSBjoern A. Zeeb mt76x2_mac_resume(dev);
466c92544dSBjoern A. Zeeb
476c92544dSBjoern A. Zeeb mt76x02_pre_tbtt_enable(dev, true);
486c92544dSBjoern A. Zeeb
496c92544dSBjoern A. Zeeb return err;
506c92544dSBjoern A. Zeeb }
516c92544dSBjoern A. Zeeb
526c92544dSBjoern A. Zeeb static int
mt76x2u_config(struct ieee80211_hw * hw,u32 changed)536c92544dSBjoern A. Zeeb mt76x2u_config(struct ieee80211_hw *hw, u32 changed)
546c92544dSBjoern A. Zeeb {
556c92544dSBjoern A. Zeeb struct mt76x02_dev *dev = hw->priv;
566c92544dSBjoern A. Zeeb int err = 0;
576c92544dSBjoern A. Zeeb
586c92544dSBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
596c92544dSBjoern A. Zeeb
606c92544dSBjoern A. Zeeb if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
616c92544dSBjoern A. Zeeb if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
626c92544dSBjoern A. Zeeb dev->mt76.rxfilter |= MT_RX_FILTR_CFG_PROMISC;
636c92544dSBjoern A. Zeeb else
646c92544dSBjoern A. Zeeb dev->mt76.rxfilter &= ~MT_RX_FILTR_CFG_PROMISC;
656c92544dSBjoern A. Zeeb mt76_wr(dev, MT_RX_FILTR_CFG, dev->mt76.rxfilter);
666c92544dSBjoern A. Zeeb }
676c92544dSBjoern A. Zeeb
686c92544dSBjoern A. Zeeb if (changed & IEEE80211_CONF_CHANGE_POWER) {
696c92544dSBjoern A. Zeeb struct mt76_phy *mphy = &dev->mphy;
706c92544dSBjoern A. Zeeb
716c92544dSBjoern A. Zeeb dev->txpower_conf = hw->conf.power_level * 2;
726c92544dSBjoern A. Zeeb dev->txpower_conf = mt76_get_sar_power(mphy,
736c92544dSBjoern A. Zeeb mphy->chandef.chan,
746c92544dSBjoern A. Zeeb dev->txpower_conf);
756c92544dSBjoern A. Zeeb /* convert to per-chain power for 2x2 devices */
766c92544dSBjoern A. Zeeb dev->txpower_conf -= 6;
776c92544dSBjoern A. Zeeb
786c92544dSBjoern A. Zeeb if (test_bit(MT76_STATE_RUNNING, &mphy->state))
796c92544dSBjoern A. Zeeb mt76x2_phy_set_txpower(dev);
806c92544dSBjoern A. Zeeb }
816c92544dSBjoern A. Zeeb
826c92544dSBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
836c92544dSBjoern A. Zeeb
84*8ba4d145SBjoern A. Zeeb if (changed & IEEE80211_CONF_CHANGE_CHANNEL)
85*8ba4d145SBjoern A. Zeeb mt76_update_channel(&dev->mphy);
866c92544dSBjoern A. Zeeb
876c92544dSBjoern A. Zeeb return err;
886c92544dSBjoern A. Zeeb }
896c92544dSBjoern A. Zeeb
906c92544dSBjoern A. Zeeb const struct ieee80211_ops mt76x2u_ops = {
91*8ba4d145SBjoern A. Zeeb .add_chanctx = ieee80211_emulate_add_chanctx,
92*8ba4d145SBjoern A. Zeeb .remove_chanctx = ieee80211_emulate_remove_chanctx,
93*8ba4d145SBjoern A. Zeeb .change_chanctx = ieee80211_emulate_change_chanctx,
94*8ba4d145SBjoern A. Zeeb .switch_vif_chanctx = ieee80211_emulate_switch_vif_chanctx,
956c92544dSBjoern A. Zeeb .tx = mt76x02_tx,
966c92544dSBjoern A. Zeeb .start = mt76x2u_start,
976c92544dSBjoern A. Zeeb .stop = mt76x2u_stop,
986c92544dSBjoern A. Zeeb .add_interface = mt76x02_add_interface,
996c92544dSBjoern A. Zeeb .remove_interface = mt76x02_remove_interface,
1006c92544dSBjoern A. Zeeb .sta_state = mt76_sta_state,
1016c92544dSBjoern A. Zeeb .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
1026c92544dSBjoern A. Zeeb .set_key = mt76x02_set_key,
1036c92544dSBjoern A. Zeeb .ampdu_action = mt76x02_ampdu_action,
1046c92544dSBjoern A. Zeeb .config = mt76x2u_config,
1056c92544dSBjoern A. Zeeb .wake_tx_queue = mt76_wake_tx_queue,
1066c92544dSBjoern A. Zeeb .bss_info_changed = mt76x02_bss_info_changed,
1076c92544dSBjoern A. Zeeb .configure_filter = mt76x02_configure_filter,
1086c92544dSBjoern A. Zeeb .conf_tx = mt76x02_conf_tx,
1096c92544dSBjoern A. Zeeb .sw_scan_start = mt76_sw_scan,
1106c92544dSBjoern A. Zeeb .sw_scan_complete = mt76x02_sw_scan_complete,
1116c92544dSBjoern A. Zeeb .sta_rate_tbl_update = mt76x02_sta_rate_tbl_update,
1126c92544dSBjoern A. Zeeb .get_txpower = mt76_get_txpower,
1136c92544dSBjoern A. Zeeb .get_survey = mt76_get_survey,
1146c92544dSBjoern A. Zeeb .set_tim = mt76_set_tim,
1156c92544dSBjoern A. Zeeb .release_buffered_frames = mt76_release_buffered_frames,
1166c92544dSBjoern A. Zeeb .get_antenna = mt76_get_antenna,
1176c92544dSBjoern A. Zeeb .set_sar_specs = mt76x2_set_sar_specs,
1186c92544dSBjoern A. Zeeb };
119