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.
20 mt76x2_start(struct ieee80211_hw *hw)
22 struct mt76x02_dev *dev = hw->priv;
25 mutex_lock(&dev->mt76.mutex);
27 ret = mt76x2_mac_start(dev);
31 ret = mt76x2_phy_start(dev);
35 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mac_work,
36 MT_CALIBRATE_INTERVAL);
38 set_bit(MT76_STATE_RUNNING, &dev->mt76.state);
41 mutex_unlock(&dev->mt76.mutex);
46 mt76x2_stop(struct ieee80211_hw *hw)
48 struct mt76x02_dev *dev = hw->priv;
50 mutex_lock(&dev->mt76.mutex);
51 clear_bit(MT76_STATE_RUNNING, &dev->mt76.state);
52 mt76x2_stop_hardware(dev);
53 mutex_unlock(&dev->mt76.mutex);
57 mt76x2_set_channel(struct mt76x02_dev *dev, struct cfg80211_chan_def *chandef)
61 cancel_delayed_work_sync(&dev->cal_work);
63 set_bit(MT76_RESET, &dev->mt76.state);
65 mt76_set_channel(&dev->mt76);
67 tasklet_disable(&dev->pre_tbtt_tasklet);
68 tasklet_disable(&dev->dfs_pd.dfs_tasklet);
70 mt76x2_mac_stop(dev, true);
71 ret = mt76x2_phy_set_channel(dev, chandef);
73 /* channel cycle counters read-and-clear */
74 mt76_rr(dev, MT_CH_IDLE);
75 mt76_rr(dev, MT_CH_BUSY);
77 mt76x2_dfs_init_params(dev);
79 mt76x2_mac_resume(dev);
80 tasklet_enable(&dev->dfs_pd.dfs_tasklet);
81 tasklet_enable(&dev->pre_tbtt_tasklet);
83 clear_bit(MT76_RESET, &dev->mt76.state);
85 mt76_txq_schedule_all(&dev->mt76);
91 mt76x2_config(struct ieee80211_hw *hw, u32 changed)
93 struct mt76x02_dev *dev = hw->priv;
96 mutex_lock(&dev->mt76.mutex);
98 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
99 if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
100 dev->mt76.rxfilter |= MT_RX_FILTR_CFG_PROMISC;
102 dev->mt76.rxfilter &= ~MT_RX_FILTR_CFG_PROMISC;
104 mt76_wr(dev, MT_RX_FILTR_CFG, dev->mt76.rxfilter);
107 if (changed & IEEE80211_CONF_CHANGE_POWER) {
108 dev->mt76.txpower_conf = hw->conf.power_level * 2;
110 /* convert to per-chain power for 2x2 devices */
111 dev->mt76.txpower_conf -= 6;
113 if (test_bit(MT76_STATE_RUNNING, &dev->mt76.state)) {
114 mt76x2_phy_set_txpower(dev);
115 mt76x02_tx_set_txpwr_auto(dev, dev->mt76.txpower_conf);
119 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
120 ieee80211_stop_queues(hw);
121 ret = mt76x2_set_channel(dev, &hw->conf.chandef);
122 ieee80211_wake_queues(hw);
125 mutex_unlock(&dev->mt76.mutex);
131 mt76x2_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
132 struct ieee80211_bss_conf *info, u32 changed)
134 struct mt76x02_dev *dev = hw->priv;
135 struct mt76x02_vif *mvif = (struct mt76x02_vif *) vif->drv_priv;
137 mutex_lock(&dev->mt76.mutex);
139 if (changed & BSS_CHANGED_BSSID)
140 mt76x2_mac_set_bssid(dev, mvif->idx, info->bssid);
142 if (changed & BSS_CHANGED_BEACON_INT) {
143 mt76_rmw_field(dev, MT_BEACON_TIME_CFG,
144 MT_BEACON_TIME_CFG_INTVAL,
145 info->beacon_int << 4);
146 dev->beacon_int = info->beacon_int;
150 if (changed & BSS_CHANGED_BEACON_ENABLED) {
151 tasklet_disable(&dev->pre_tbtt_tasklet);
152 mt76x2_mac_set_beacon_enable(dev, mvif->idx,
153 info->enable_beacon);
154 tasklet_enable(&dev->pre_tbtt_tasklet);
157 if (changed & BSS_CHANGED_ERP_SLOT) {
158 int slottime = info->use_short_slot ? 9 : 20;
160 dev->slottime = slottime;
161 mt76x2_set_tx_ackto(dev);
164 mutex_unlock(&dev->mt76.mutex);
168 mt76x2_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps)
170 struct mt76x02_sta *msta = (struct mt76x02_sta *) sta->drv_priv;
171 struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76);
172 int idx = msta->wcid.idx;
174 mt76_stop_tx_queues(&dev->mt76, sta, true);
175 mt76x02_mac_wcid_set_drop(dev, idx, ps);
179 mt76x2_sw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
182 struct mt76x02_dev *dev = hw->priv;
184 tasklet_disable(&dev->pre_tbtt_tasklet);
185 set_bit(MT76_SCANNING, &dev->mt76.state);
189 mt76x2_sw_scan_complete(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
191 struct mt76x02_dev *dev = hw->priv;
193 clear_bit(MT76_SCANNING, &dev->mt76.state);
194 tasklet_enable(&dev->pre_tbtt_tasklet);
198 mt76x2_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
199 u32 queues, bool drop)
204 mt76x2_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif, int *dbm)
206 struct mt76x02_dev *dev = hw->priv;
208 *dbm = dev->mt76.txpower_cur / 2;
210 /* convert from per-chain power to combined output on 2x2 devices */
216 static void mt76x2_set_coverage_class(struct ieee80211_hw *hw,
219 struct mt76x02_dev *dev = hw->priv;
221 mutex_lock(&dev->mt76.mutex);
222 dev->coverage_class = coverage_class;
223 mt76x2_set_tx_ackto(dev);
224 mutex_unlock(&dev->mt76.mutex);
228 mt76x2_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
233 static int mt76x2_set_antenna(struct ieee80211_hw *hw, u32 tx_ant,
236 struct mt76x02_dev *dev = hw->priv;
238 if (!tx_ant || tx_ant > 3 || tx_ant != rx_ant)
241 mutex_lock(&dev->mt76.mutex);
243 dev->mt76.chainmask = (tx_ant == 3) ? 0x202 : 0x101;
244 dev->mt76.antenna_mask = tx_ant;
246 mt76_set_stream_caps(&dev->mt76, true);
247 mt76x2_phy_set_antenna(dev);
249 mutex_unlock(&dev->mt76.mutex);
254 static int mt76x2_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant,
257 struct mt76x02_dev *dev = hw->priv;
259 mutex_lock(&dev->mt76.mutex);
260 *tx_ant = dev->mt76.antenna_mask;
261 *rx_ant = dev->mt76.antenna_mask;
262 mutex_unlock(&dev->mt76.mutex);
268 mt76x2_set_rts_threshold(struct ieee80211_hw *hw, u32 val)
270 struct mt76x02_dev *dev = hw->priv;
272 if (val != ~0 && val > 0xffff)
275 mutex_lock(&dev->mt76.mutex);
276 mt76x2_mac_set_tx_protection(dev, val);
277 mutex_unlock(&dev->mt76.mutex);
282 const struct ieee80211_ops mt76x2_ops = {
284 .start = mt76x2_start,
286 .add_interface = mt76x02_add_interface,
287 .remove_interface = mt76x02_remove_interface,
288 .config = mt76x2_config,
289 .configure_filter = mt76x02_configure_filter,
290 .bss_info_changed = mt76x2_bss_info_changed,
291 .sta_add = mt76x02_sta_add,
292 .sta_remove = mt76x02_sta_remove,
293 .set_key = mt76x02_set_key,
294 .conf_tx = mt76x02_conf_tx,
295 .sw_scan_start = mt76x2_sw_scan,
296 .sw_scan_complete = mt76x2_sw_scan_complete,
297 .flush = mt76x2_flush,
298 .ampdu_action = mt76x02_ampdu_action,
299 .get_txpower = mt76x2_get_txpower,
300 .wake_tx_queue = mt76_wake_tx_queue,
301 .sta_rate_tbl_update = mt76x02_sta_rate_tbl_update,
302 .release_buffered_frames = mt76_release_buffered_frames,
303 .set_coverage_class = mt76x2_set_coverage_class,
304 .get_survey = mt76_get_survey,
305 .set_tim = mt76x2_set_tim,
306 .set_antenna = mt76x2_set_antenna,
307 .get_antenna = mt76x2_get_antenna,
308 .set_rts_threshold = mt76x2_set_rts_threshold,