2018-07-31 10:09:20 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mt76x2u.h"
|
|
|
|
|
|
|
|
static int mt76x2u_start(struct ieee80211_hw *hw)
|
|
|
|
{
|
2018-10-04 23:53:08 +02:00
|
|
|
struct mt76x02_dev *dev = hw->priv;
|
2018-07-31 10:09:20 +02:00
|
|
|
int ret;
|
|
|
|
|
2018-08-29 13:16:35 +02:00
|
|
|
mutex_lock(&dev->mt76.mutex);
|
2018-07-31 10:09:20 +02:00
|
|
|
|
|
|
|
ret = mt76x2u_mac_start(dev);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2018-10-15 11:33:16 +02:00
|
|
|
ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mac_work,
|
2019-02-03 14:13:06 +01:00
|
|
|
MT_MAC_WORK_INTERVAL);
|
2018-07-31 10:09:20 +02:00
|
|
|
set_bit(MT76_STATE_RUNNING, &dev->mt76.state);
|
|
|
|
|
|
|
|
out:
|
2018-08-29 13:16:35 +02:00
|
|
|
mutex_unlock(&dev->mt76.mutex);
|
2018-07-31 10:09:20 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mt76x2u_stop(struct ieee80211_hw *hw)
|
|
|
|
{
|
2018-10-04 23:53:08 +02:00
|
|
|
struct mt76x02_dev *dev = hw->priv;
|
2018-07-31 10:09:20 +02:00
|
|
|
|
2018-08-29 13:16:35 +02:00
|
|
|
mutex_lock(&dev->mt76.mutex);
|
2018-07-31 10:09:20 +02:00
|
|
|
clear_bit(MT76_STATE_RUNNING, &dev->mt76.state);
|
|
|
|
mt76x2u_stop_hw(dev);
|
2018-08-29 13:16:35 +02:00
|
|
|
mutex_unlock(&dev->mt76.mutex);
|
2018-07-31 10:09:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2018-10-04 23:53:08 +02:00
|
|
|
mt76x2u_set_channel(struct mt76x02_dev *dev,
|
2018-07-31 10:09:20 +02:00
|
|
|
struct cfg80211_chan_def *chandef)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
cancel_delayed_work_sync(&dev->cal_work);
|
|
|
|
set_bit(MT76_RESET, &dev->mt76.state);
|
|
|
|
|
|
|
|
mt76_set_channel(&dev->mt76);
|
|
|
|
|
|
|
|
mt76x2_mac_stop(dev, false);
|
|
|
|
|
|
|
|
err = mt76x2u_phy_set_channel(dev, chandef);
|
|
|
|
|
|
|
|
mt76x2u_mac_resume(dev);
|
2019-02-25 17:25:38 +01:00
|
|
|
mt76x02_edcca_init(dev, true);
|
2018-07-31 10:09:20 +02:00
|
|
|
|
|
|
|
clear_bit(MT76_RESET, &dev->mt76.state);
|
|
|
|
mt76_txq_schedule_all(&dev->mt76);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mt76x2u_config(struct ieee80211_hw *hw, u32 changed)
|
|
|
|
{
|
2018-10-04 23:53:08 +02:00
|
|
|
struct mt76x02_dev *dev = hw->priv;
|
2018-07-31 10:09:20 +02:00
|
|
|
int err = 0;
|
|
|
|
|
2018-08-29 13:16:35 +02:00
|
|
|
mutex_lock(&dev->mt76.mutex);
|
2018-07-31 10:09:20 +02:00
|
|
|
|
|
|
|
if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
|
|
|
|
if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
|
2018-08-29 13:16:35 +02:00
|
|
|
dev->mt76.rxfilter |= MT_RX_FILTR_CFG_PROMISC;
|
2018-07-31 10:09:20 +02:00
|
|
|
else
|
2018-08-29 13:16:35 +02:00
|
|
|
dev->mt76.rxfilter &= ~MT_RX_FILTR_CFG_PROMISC;
|
|
|
|
mt76_wr(dev, MT_RX_FILTR_CFG, dev->mt76.rxfilter);
|
2018-07-31 10:09:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
|
|
|
|
ieee80211_stop_queues(hw);
|
|
|
|
err = mt76x2u_set_channel(dev, &hw->conf.chandef);
|
|
|
|
ieee80211_wake_queues(hw);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed & IEEE80211_CONF_CHANGE_POWER) {
|
2018-09-22 13:45:29 +02:00
|
|
|
dev->mt76.txpower_conf = hw->conf.power_level * 2;
|
2018-07-31 10:09:20 +02:00
|
|
|
|
|
|
|
/* convert to per-chain power for 2x2 devices */
|
2018-09-22 13:45:29 +02:00
|
|
|
dev->mt76.txpower_conf -= 6;
|
2018-07-31 10:09:20 +02:00
|
|
|
|
|
|
|
if (test_bit(MT76_STATE_RUNNING, &dev->mt76.state))
|
|
|
|
mt76x2_phy_set_txpower(dev);
|
|
|
|
}
|
|
|
|
|
2018-08-29 13:16:35 +02:00
|
|
|
mutex_unlock(&dev->mt76.mutex);
|
2018-07-31 10:09:20 +02:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct ieee80211_ops mt76x2u_ops = {
|
2018-10-04 23:53:12 +02:00
|
|
|
.tx = mt76x02_tx,
|
2018-07-31 10:09:20 +02:00
|
|
|
.start = mt76x2u_start,
|
|
|
|
.stop = mt76x2u_stop,
|
2019-01-30 17:02:14 +01:00
|
|
|
.add_interface = mt76x02_add_interface,
|
2018-09-04 16:41:05 +02:00
|
|
|
.remove_interface = mt76x02_remove_interface,
|
2018-11-16 10:49:14 +01:00
|
|
|
.sta_state = mt76_sta_state,
|
2018-09-04 16:40:59 +02:00
|
|
|
.set_key = mt76x02_set_key,
|
2018-09-04 16:40:58 +02:00
|
|
|
.ampdu_action = mt76x02_ampdu_action,
|
2018-07-31 10:09:20 +02:00
|
|
|
.config = mt76x2u_config,
|
|
|
|
.wake_tx_queue = mt76_wake_tx_queue,
|
2018-11-06 17:59:47 +01:00
|
|
|
.bss_info_changed = mt76x02_bss_info_changed,
|
2018-08-29 13:16:35 +02:00
|
|
|
.configure_filter = mt76x02_configure_filter,
|
2018-09-04 16:41:03 +02:00
|
|
|
.conf_tx = mt76x02_conf_tx,
|
2018-10-20 12:13:28 +02:00
|
|
|
.sw_scan_start = mt76x02_sw_scan,
|
|
|
|
.sw_scan_complete = mt76x02_sw_scan_complete,
|
2018-09-04 16:41:07 +02:00
|
|
|
.sta_rate_tbl_update = mt76x02_sta_rate_tbl_update,
|
2018-12-06 14:27:34 +01:00
|
|
|
.get_txpower = mt76_get_txpower,
|
2018-07-31 10:09:20 +02:00
|
|
|
};
|