0001
0002
0003
0004
0005
0006 #include "mt76x2.h"
0007 #include "../mt76x02_mac.h"
0008
0009 static int
0010 mt76x2_start(struct ieee80211_hw *hw)
0011 {
0012 struct mt76x02_dev *dev = hw->priv;
0013
0014 mt76x02_mac_start(dev);
0015 mt76x2_phy_start(dev);
0016
0017 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work,
0018 MT_MAC_WORK_INTERVAL);
0019 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->wdt_work,
0020 MT_WATCHDOG_TIME);
0021
0022 set_bit(MT76_STATE_RUNNING, &dev->mphy.state);
0023 return 0;
0024 }
0025
0026 static void
0027 mt76x2_stop(struct ieee80211_hw *hw)
0028 {
0029 struct mt76x02_dev *dev = hw->priv;
0030
0031 clear_bit(MT76_STATE_RUNNING, &dev->mphy.state);
0032 mt76x2_stop_hardware(dev);
0033 }
0034
0035 static void
0036 mt76x2_set_channel(struct mt76x02_dev *dev, struct cfg80211_chan_def *chandef)
0037 {
0038 cancel_delayed_work_sync(&dev->cal_work);
0039 tasklet_disable(&dev->mt76.pre_tbtt_tasklet);
0040 tasklet_disable(&dev->dfs_pd.dfs_tasklet);
0041
0042 mutex_lock(&dev->mt76.mutex);
0043 set_bit(MT76_RESET, &dev->mphy.state);
0044
0045 mt76_set_channel(&dev->mphy);
0046
0047 mt76x2_mac_stop(dev, true);
0048 mt76x2_phy_set_channel(dev, chandef);
0049
0050 mt76x02_mac_cc_reset(dev);
0051 mt76x02_dfs_init_params(dev);
0052
0053 mt76x2_mac_resume(dev);
0054
0055 clear_bit(MT76_RESET, &dev->mphy.state);
0056 mutex_unlock(&dev->mt76.mutex);
0057
0058 tasklet_enable(&dev->dfs_pd.dfs_tasklet);
0059 tasklet_enable(&dev->mt76.pre_tbtt_tasklet);
0060
0061 mt76_txq_schedule_all(&dev->mphy);
0062 }
0063
0064 static int
0065 mt76x2_config(struct ieee80211_hw *hw, u32 changed)
0066 {
0067 struct mt76x02_dev *dev = hw->priv;
0068
0069 mutex_lock(&dev->mt76.mutex);
0070
0071 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
0072 if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
0073 dev->mt76.rxfilter |= MT_RX_FILTR_CFG_PROMISC;
0074 else
0075 dev->mt76.rxfilter &= ~MT_RX_FILTR_CFG_PROMISC;
0076
0077 mt76_wr(dev, MT_RX_FILTR_CFG, dev->mt76.rxfilter);
0078 }
0079
0080 if (changed & IEEE80211_CONF_CHANGE_POWER) {
0081 struct mt76_phy *mphy = &dev->mphy;
0082
0083 dev->txpower_conf = hw->conf.power_level * 2;
0084 dev->txpower_conf = mt76_get_sar_power(mphy,
0085 mphy->chandef.chan,
0086 dev->txpower_conf);
0087
0088 dev->txpower_conf -= 6;
0089
0090 if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) {
0091 mt76x2_phy_set_txpower(dev);
0092 mt76x02_tx_set_txpwr_auto(dev, dev->txpower_conf);
0093 }
0094 }
0095
0096 mutex_unlock(&dev->mt76.mutex);
0097
0098 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
0099 ieee80211_stop_queues(hw);
0100 mt76x2_set_channel(dev, &hw->conf.chandef);
0101 ieee80211_wake_queues(hw);
0102 }
0103
0104 return 0;
0105 }
0106
0107 static void
0108 mt76x2_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
0109 u32 queues, bool drop)
0110 {
0111 }
0112
0113 static int mt76x2_set_antenna(struct ieee80211_hw *hw, u32 tx_ant,
0114 u32 rx_ant)
0115 {
0116 struct mt76x02_dev *dev = hw->priv;
0117
0118 if (!tx_ant || tx_ant > 3 || tx_ant != rx_ant)
0119 return -EINVAL;
0120
0121 mutex_lock(&dev->mt76.mutex);
0122
0123 dev->mphy.chainmask = (tx_ant == 3) ? 0x202 : 0x101;
0124 dev->mphy.antenna_mask = tx_ant;
0125
0126 mt76_set_stream_caps(&dev->mphy, true);
0127 mt76x2_phy_set_antenna(dev);
0128
0129 mutex_unlock(&dev->mt76.mutex);
0130
0131 return 0;
0132 }
0133
0134 const struct ieee80211_ops mt76x2_ops = {
0135 .tx = mt76x02_tx,
0136 .start = mt76x2_start,
0137 .stop = mt76x2_stop,
0138 .add_interface = mt76x02_add_interface,
0139 .remove_interface = mt76x02_remove_interface,
0140 .config = mt76x2_config,
0141 .configure_filter = mt76x02_configure_filter,
0142 .bss_info_changed = mt76x02_bss_info_changed,
0143 .sta_state = mt76_sta_state,
0144 .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
0145 .set_key = mt76x02_set_key,
0146 .conf_tx = mt76x02_conf_tx,
0147 .sw_scan_start = mt76_sw_scan,
0148 .sw_scan_complete = mt76x02_sw_scan_complete,
0149 .flush = mt76x2_flush,
0150 .ampdu_action = mt76x02_ampdu_action,
0151 .get_txpower = mt76_get_txpower,
0152 .wake_tx_queue = mt76_wake_tx_queue,
0153 .sta_rate_tbl_update = mt76x02_sta_rate_tbl_update,
0154 .release_buffered_frames = mt76_release_buffered_frames,
0155 .set_coverage_class = mt76x02_set_coverage_class,
0156 .get_survey = mt76_get_survey,
0157 .set_tim = mt76_set_tim,
0158 .set_antenna = mt76x2_set_antenna,
0159 .get_antenna = mt76_get_antenna,
0160 .set_rts_threshold = mt76x02_set_rts_threshold,
0161 .reconfig_complete = mt76x02_reconfig_complete,
0162 .set_sar_specs = mt76x2_set_sar_specs,
0163 };
0164