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 mt76x2_dev *dev = hw->priv;
24 mutex_lock(&dev->mutex);
26 ret = mt76x2u_mac_start(dev);
30 set_bit(MT76_STATE_RUNNING, &dev->mt76.state);
33 mutex_unlock(&dev->mutex);
37 static void mt76x2u_stop(struct ieee80211_hw *hw)
39 struct mt76x2_dev *dev = hw->priv;
41 mutex_lock(&dev->mutex);
42 clear_bit(MT76_STATE_RUNNING, &dev->mt76.state);
44 mutex_unlock(&dev->mutex);
47 static int mt76x2u_add_interface(struct ieee80211_hw *hw,
48 struct ieee80211_vif *vif)
50 struct mt76x2_dev *dev = hw->priv;
51 struct mt76x2_vif *mvif = (struct mt76x2_vif *)vif->drv_priv;
54 if (!ether_addr_equal(dev->mt76.macaddr, vif->addr))
55 mt76x2u_mac_setaddr(dev, vif->addr);
58 mvif->group_wcid.idx = MT_VIF_WCID(idx);
59 mvif->group_wcid.hw_key_idx = -1;
60 mt76x2_txq_init(dev, vif->txq);
66 mt76x2u_set_channel(struct mt76x2_dev *dev,
67 struct cfg80211_chan_def *chandef)
71 cancel_delayed_work_sync(&dev->cal_work);
72 set_bit(MT76_RESET, &dev->mt76.state);
74 mt76_set_channel(&dev->mt76);
76 mt76_clear(dev, MT_TXOP_CTRL_CFG, BIT(20));
77 mt76_clear(dev, MT_TXOP_HLDR_ET, BIT(1));
78 mt76x2_mac_stop(dev, false);
80 err = mt76x2u_phy_set_channel(dev, chandef);
82 mt76x2u_mac_resume(dev);
84 clear_bit(MT76_RESET, &dev->mt76.state);
85 mt76_txq_schedule_all(&dev->mt76);
91 mt76x2u_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
92 struct ieee80211_bss_conf *info, u32 changed)
94 struct mt76x2_dev *dev = hw->priv;
96 mutex_lock(&dev->mutex);
98 if (changed & BSS_CHANGED_ASSOC) {
99 mt76x2u_phy_channel_calibrate(dev);
100 mt76x2_apply_gain_adj(dev);
103 if (changed & BSS_CHANGED_BSSID) {
104 mt76_wr(dev, MT_MAC_BSSID_DW0,
105 get_unaligned_le32(info->bssid));
106 mt76_wr(dev, MT_MAC_BSSID_DW1,
107 get_unaligned_le16(info->bssid + 4));
110 mutex_unlock(&dev->mutex);
114 mt76x2u_config(struct ieee80211_hw *hw, u32 changed)
116 struct mt76x2_dev *dev = hw->priv;
119 mutex_lock(&dev->mutex);
121 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
122 if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
123 dev->rxfilter |= MT_RX_FILTR_CFG_PROMISC;
125 dev->rxfilter &= ~MT_RX_FILTR_CFG_PROMISC;
126 mt76_wr(dev, MT_RX_FILTR_CFG, dev->rxfilter);
129 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
130 ieee80211_stop_queues(hw);
131 err = mt76x2u_set_channel(dev, &hw->conf.chandef);
132 ieee80211_wake_queues(hw);
135 if (changed & IEEE80211_CONF_CHANGE_POWER) {
136 dev->txpower_conf = hw->conf.power_level * 2;
138 /* convert to per-chain power for 2x2 devices */
139 dev->txpower_conf -= 6;
141 if (test_bit(MT76_STATE_RUNNING, &dev->mt76.state))
142 mt76x2_phy_set_txpower(dev);
145 mutex_unlock(&dev->mutex);
151 mt76x2u_sw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
154 struct mt76x2_dev *dev = hw->priv;
156 set_bit(MT76_SCANNING, &dev->mt76.state);
160 mt76x2u_sw_scan_complete(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
162 struct mt76x2_dev *dev = hw->priv;
164 clear_bit(MT76_SCANNING, &dev->mt76.state);
167 const struct ieee80211_ops mt76x2u_ops = {
169 .start = mt76x2u_start,
170 .stop = mt76x2u_stop,
171 .add_interface = mt76x2u_add_interface,
172 .remove_interface = mt76x2_remove_interface,
173 .sta_add = mt76x2_sta_add,
174 .sta_remove = mt76x2_sta_remove,
175 .set_key = mt76x2_set_key,
176 .ampdu_action = mt76x2_ampdu_action,
177 .config = mt76x2u_config,
178 .wake_tx_queue = mt76_wake_tx_queue,
179 .bss_info_changed = mt76x2u_bss_info_changed,
180 .configure_filter = mt76x2_configure_filter,
181 .conf_tx = mt76x2_conf_tx,
182 .sw_scan_start = mt76x2u_sw_scan,
183 .sw_scan_complete = mt76x2u_sw_scan_complete,
184 .sta_rate_tbl_update = mt76x2_sta_rate_tbl_update,