2019-07-24 08:58:20 +00:00
|
|
|
// SPDX-License-Identifier: ISC
|
2017-11-21 09:50:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mt76x2.h"
|
2019-09-12 09:06:36 +00:00
|
|
|
#include "../mt76x02_mac.h"
|
2017-11-21 09:50:53 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
mt76x2_start(struct ieee80211_hw *hw)
|
|
|
|
{
|
2018-10-04 21:53:08 +00:00
|
|
|
struct mt76x02_dev *dev = hw->priv;
|
2017-11-21 09:50:53 +00:00
|
|
|
|
2019-09-12 09:06:36 +00:00
|
|
|
mt76x02_mac_start(dev);
|
2020-02-16 15:08:58 +00:00
|
|
|
mt76x2_phy_start(dev);
|
2017-11-21 09:50:53 +00:00
|
|
|
|
2019-03-18 10:21:44 +00:00
|
|
|
ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mt76.mac_work,
|
2019-02-03 13:13:06 +00:00
|
|
|
MT_MAC_WORK_INTERVAL);
|
2018-12-28 14:44:09 +00:00
|
|
|
ieee80211_queue_delayed_work(mt76_hw(dev), &dev->wdt_work,
|
|
|
|
MT_WATCHDOG_TIME);
|
2017-11-21 09:50:53 +00:00
|
|
|
|
2019-10-16 10:09:22 +00:00
|
|
|
set_bit(MT76_STATE_RUNNING, &dev->mphy.state);
|
2019-04-26 07:58:42 +00:00
|
|
|
return 0;
|
2017-11-21 09:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mt76x2_stop(struct ieee80211_hw *hw)
|
|
|
|
{
|
2018-10-04 21:53:08 +00:00
|
|
|
struct mt76x02_dev *dev = hw->priv;
|
2017-11-21 09:50:53 +00:00
|
|
|
|
2019-10-16 10:09:22 +00:00
|
|
|
clear_bit(MT76_STATE_RUNNING, &dev->mphy.state);
|
2017-11-21 09:50:53 +00:00
|
|
|
mt76x2_stop_hardware(dev);
|
|
|
|
}
|
|
|
|
|
2020-02-16 15:08:58 +00:00
|
|
|
static void
|
2018-10-04 21:53:08 +00:00
|
|
|
mt76x2_set_channel(struct mt76x02_dev *dev, struct cfg80211_chan_def *chandef)
|
2017-11-21 09:50:53 +00:00
|
|
|
{
|
2018-05-20 05:43:46 +00:00
|
|
|
cancel_delayed_work_sync(&dev->cal_work);
|
2019-05-11 10:17:53 +00:00
|
|
|
tasklet_disable(&dev->mt76.pre_tbtt_tasklet);
|
|
|
|
tasklet_disable(&dev->dfs_pd.dfs_tasklet);
|
2018-05-20 05:43:46 +00:00
|
|
|
|
2019-05-11 10:17:53 +00:00
|
|
|
mutex_lock(&dev->mt76.mutex);
|
2019-10-16 10:09:22 +00:00
|
|
|
set_bit(MT76_RESET, &dev->mphy.state);
|
2018-05-20 05:43:46 +00:00
|
|
|
|
2019-10-12 17:46:40 +00:00
|
|
|
mt76_set_channel(&dev->mphy);
|
2017-11-21 09:50:53 +00:00
|
|
|
|
|
|
|
mt76x2_mac_stop(dev, true);
|
2020-02-16 15:08:58 +00:00
|
|
|
mt76x2_phy_set_channel(dev, chandef);
|
2017-11-21 09:50:53 +00:00
|
|
|
|
2019-09-05 16:29:13 +00:00
|
|
|
mt76x02_mac_cc_reset(dev);
|
2018-10-22 21:42:12 +00:00
|
|
|
mt76x02_dfs_init_params(dev);
|
2017-11-21 09:50:53 +00:00
|
|
|
|
|
|
|
mt76x2_mac_resume(dev);
|
|
|
|
|
2019-10-16 10:09:22 +00:00
|
|
|
clear_bit(MT76_RESET, &dev->mphy.state);
|
2019-05-11 10:17:53 +00:00
|
|
|
mutex_unlock(&dev->mt76.mutex);
|
|
|
|
|
|
|
|
tasklet_enable(&dev->dfs_pd.dfs_tasklet);
|
|
|
|
tasklet_enable(&dev->mt76.pre_tbtt_tasklet);
|
2018-05-20 05:43:46 +00:00
|
|
|
|
2019-10-11 21:27:20 +00:00
|
|
|
mt76_txq_schedule_all(&dev->mphy);
|
2017-11-21 09:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mt76x2_config(struct ieee80211_hw *hw, u32 changed)
|
|
|
|
{
|
2018-10-04 21:53:08 +00:00
|
|
|
struct mt76x02_dev *dev = hw->priv;
|
2017-11-21 09:50:53 +00:00
|
|
|
|
2018-08-29 11:16:35 +00:00
|
|
|
mutex_lock(&dev->mt76.mutex);
|
2017-11-21 09:50:53 +00:00
|
|
|
|
2017-12-14 15:39:17 +00:00
|
|
|
if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
|
|
|
|
if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
|
2018-08-29 11:16:35 +00:00
|
|
|
dev->mt76.rxfilter |= MT_RX_FILTR_CFG_PROMISC;
|
2017-12-14 15:39:17 +00:00
|
|
|
else
|
2018-08-29 11:16:35 +00:00
|
|
|
dev->mt76.rxfilter &= ~MT_RX_FILTR_CFG_PROMISC;
|
2017-12-14 15:39:17 +00:00
|
|
|
|
2018-08-29 11:16:35 +00:00
|
|
|
mt76_wr(dev, MT_RX_FILTR_CFG, dev->mt76.rxfilter);
|
2017-12-14 15:39:17 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 09:50:53 +00:00
|
|
|
if (changed & IEEE80211_CONF_CHANGE_POWER) {
|
2019-10-16 10:36:16 +00:00
|
|
|
dev->txpower_conf = hw->conf.power_level * 2;
|
2017-11-21 09:50:53 +00:00
|
|
|
|
2017-12-14 15:39:12 +00:00
|
|
|
/* convert to per-chain power for 2x2 devices */
|
2019-10-16 10:36:16 +00:00
|
|
|
dev->txpower_conf -= 6;
|
2017-12-14 15:39:12 +00:00
|
|
|
|
2019-10-16 10:09:22 +00:00
|
|
|
if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) {
|
2017-11-21 09:50:53 +00:00
|
|
|
mt76x2_phy_set_txpower(dev);
|
2019-10-16 10:36:16 +00:00
|
|
|
mt76x02_tx_set_txpwr_auto(dev, dev->txpower_conf);
|
2017-11-21 09:50:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-11 10:17:53 +00:00
|
|
|
mutex_unlock(&dev->mt76.mutex);
|
|
|
|
|
2017-11-21 09:50:53 +00:00
|
|
|
if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
|
|
|
|
ieee80211_stop_queues(hw);
|
2020-02-16 15:08:58 +00:00
|
|
|
mt76x2_set_channel(dev, &hw->conf.chandef);
|
2017-11-21 09:50:53 +00:00
|
|
|
ieee80211_wake_queues(hw);
|
|
|
|
}
|
|
|
|
|
2020-02-16 15:08:58 +00:00
|
|
|
return 0;
|
2017-11-21 09:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mt76x2_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
|
|
|
|
u32 queues, bool drop)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-24 15:54:14 +00:00
|
|
|
static int mt76x2_set_antenna(struct ieee80211_hw *hw, u32 tx_ant,
|
|
|
|
u32 rx_ant)
|
|
|
|
{
|
2018-10-04 21:53:08 +00:00
|
|
|
struct mt76x02_dev *dev = hw->priv;
|
2018-02-24 15:54:14 +00:00
|
|
|
|
|
|
|
if (!tx_ant || tx_ant > 3 || tx_ant != rx_ant)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2018-08-29 11:16:35 +00:00
|
|
|
mutex_lock(&dev->mt76.mutex);
|
2018-02-24 15:54:14 +00:00
|
|
|
|
2019-10-16 10:31:46 +00:00
|
|
|
dev->chainmask = (tx_ant == 3) ? 0x202 : 0x101;
|
2019-10-16 10:41:48 +00:00
|
|
|
dev->mphy.antenna_mask = tx_ant;
|
2018-02-24 15:54:14 +00:00
|
|
|
|
2020-04-24 19:32:39 +00:00
|
|
|
mt76_set_stream_caps(&dev->mphy, true);
|
2018-02-24 15:54:14 +00:00
|
|
|
mt76x2_phy_set_antenna(dev);
|
|
|
|
|
2018-08-29 11:16:35 +00:00
|
|
|
mutex_unlock(&dev->mt76.mutex);
|
2018-02-24 15:54:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-21 09:50:53 +00:00
|
|
|
const struct ieee80211_ops mt76x2_ops = {
|
2018-10-04 21:53:12 +00:00
|
|
|
.tx = mt76x02_tx,
|
2017-11-21 09:50:53 +00:00
|
|
|
.start = mt76x2_start,
|
|
|
|
.stop = mt76x2_stop,
|
2018-09-04 14:41:06 +00:00
|
|
|
.add_interface = mt76x02_add_interface,
|
2018-09-04 14:41:05 +00:00
|
|
|
.remove_interface = mt76x02_remove_interface,
|
2017-11-21 09:50:53 +00:00
|
|
|
.config = mt76x2_config,
|
2018-08-29 11:16:35 +00:00
|
|
|
.configure_filter = mt76x02_configure_filter,
|
2018-10-20 10:40:55 +00:00
|
|
|
.bss_info_changed = mt76x02_bss_info_changed,
|
2018-11-16 09:49:14 +00:00
|
|
|
.sta_state = mt76_sta_state,
|
2020-02-06 17:30:08 +00:00
|
|
|
.sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
|
2018-09-04 14:40:59 +00:00
|
|
|
.set_key = mt76x02_set_key,
|
2018-09-04 14:41:03 +00:00
|
|
|
.conf_tx = mt76x02_conf_tx,
|
2019-08-21 08:00:19 +00:00
|
|
|
.sw_scan_start = mt76_sw_scan,
|
2018-10-20 10:13:28 +00:00
|
|
|
.sw_scan_complete = mt76x02_sw_scan_complete,
|
2017-11-21 09:50:53 +00:00
|
|
|
.flush = mt76x2_flush,
|
2018-09-04 14:40:58 +00:00
|
|
|
.ampdu_action = mt76x02_ampdu_action,
|
2018-12-06 13:27:34 +00:00
|
|
|
.get_txpower = mt76_get_txpower,
|
2017-11-21 09:50:53 +00:00
|
|
|
.wake_tx_queue = mt76_wake_tx_queue,
|
2018-09-04 14:41:07 +00:00
|
|
|
.sta_rate_tbl_update = mt76x02_sta_rate_tbl_update,
|
2017-11-21 09:50:53 +00:00
|
|
|
.release_buffered_frames = mt76_release_buffered_frames,
|
2018-10-20 10:40:52 +00:00
|
|
|
.set_coverage_class = mt76x02_set_coverage_class,
|
2017-11-21 09:50:53 +00:00
|
|
|
.get_survey = mt76_get_survey,
|
2019-03-19 10:37:46 +00:00
|
|
|
.set_tim = mt76_set_tim,
|
2018-02-24 15:54:14 +00:00
|
|
|
.set_antenna = mt76x2_set_antenna,
|
2019-11-14 15:12:07 +00:00
|
|
|
.get_antenna = mt76_get_antenna,
|
2018-10-20 10:40:54 +00:00
|
|
|
.set_rts_threshold = mt76x02_set_rts_threshold,
|
2020-02-16 15:08:58 +00:00
|
|
|
.reconfig_complete = mt76x02_reconfig_complete,
|
2017-11-21 09:50:53 +00:00
|
|
|
};
|
|
|
|
|