2 * Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 static int mt76x2u_start(struct ieee80211_hw *hw)
21 struct mt76x02_dev *dev = hw->priv;
24 mutex_lock(&dev->mt76.mutex);
26 ret = mt76x2u_mac_start(dev);
30 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mac_work,
31 MT_CALIBRATE_INTERVAL);
32 set_bit(MT76_STATE_RUNNING, &dev->mt76.state);
35 mutex_unlock(&dev->mt76.mutex);
39 static void mt76x2u_stop(struct ieee80211_hw *hw)
41 struct mt76x02_dev *dev = hw->priv;
43 mutex_lock(&dev->mt76.mutex);
44 clear_bit(MT76_STATE_RUNNING, &dev->mt76.state);
46 mutex_unlock(&dev->mt76.mutex);
49 static int mt76x2u_add_interface(struct ieee80211_hw *hw,
50 struct ieee80211_vif *vif)
52 struct mt76x02_dev *dev = hw->priv;
55 if (!ether_addr_equal(dev->mt76.macaddr, vif->addr))
56 mt76x02_mac_setaddr(dev, vif->addr);
58 mt76x02_vif_init(dev, vif, idx);
63 mt76x2u_set_channel(struct mt76x02_dev *dev,
64 struct cfg80211_chan_def *chandef)
68 cancel_delayed_work_sync(&dev->cal_work);
69 set_bit(MT76_RESET, &dev->mt76.state);
71 mt76_set_channel(&dev->mt76);
73 mt76_clear(dev, MT_TXOP_CTRL_CFG, BIT(20));
74 mt76_clear(dev, MT_TXOP_HLDR_ET, BIT(1));
75 mt76x2_mac_stop(dev, false);
77 err = mt76x2u_phy_set_channel(dev, chandef);
79 mt76x2u_mac_resume(dev);
81 clear_bit(MT76_RESET, &dev->mt76.state);
82 mt76_txq_schedule_all(&dev->mt76);
88 mt76x2u_config(struct ieee80211_hw *hw, u32 changed)
90 struct mt76x02_dev *dev = hw->priv;
93 mutex_lock(&dev->mt76.mutex);
95 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
96 if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
97 dev->mt76.rxfilter |= MT_RX_FILTR_CFG_PROMISC;
99 dev->mt76.rxfilter &= ~MT_RX_FILTR_CFG_PROMISC;
100 mt76_wr(dev, MT_RX_FILTR_CFG, dev->mt76.rxfilter);
103 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
104 ieee80211_stop_queues(hw);
105 err = mt76x2u_set_channel(dev, &hw->conf.chandef);
106 ieee80211_wake_queues(hw);
109 if (changed & IEEE80211_CONF_CHANGE_POWER) {
110 dev->mt76.txpower_conf = hw->conf.power_level * 2;
112 /* convert to per-chain power for 2x2 devices */
113 dev->mt76.txpower_conf -= 6;
115 if (test_bit(MT76_STATE_RUNNING, &dev->mt76.state))
116 mt76x2_phy_set_txpower(dev);
119 mutex_unlock(&dev->mt76.mutex);
124 const struct ieee80211_ops mt76x2u_ops = {
126 .start = mt76x2u_start,
127 .stop = mt76x2u_stop,
128 .add_interface = mt76x2u_add_interface,
129 .remove_interface = mt76x02_remove_interface,
130 .sta_state = mt76_sta_state,
131 .set_key = mt76x02_set_key,
132 .ampdu_action = mt76x02_ampdu_action,
133 .config = mt76x2u_config,
134 .wake_tx_queue = mt76_wake_tx_queue,
135 .bss_info_changed = mt76x02_bss_info_changed,
136 .configure_filter = mt76x02_configure_filter,
137 .conf_tx = mt76x02_conf_tx,
138 .sw_scan_start = mt76x02_sw_scan,
139 .sw_scan_complete = mt76x02_sw_scan_complete,
140 .sta_rate_tbl_update = mt76x02_sta_rate_tbl_update,
141 .get_txpower = mt76x02_get_txpower,