1 // SPDX-License-Identifier: ISC
2 /* Copyright (C) 2019 MediaTek Inc.
3  *
4  * Author: Roy Luo <royluo@google.com>
5  *         Ryder Lee <ryder.lee@mediatek.com>
6  *         Felix Fietkau <nbd@nbd.name>
7  *         Lorenzo Bianconi <lorenzo@kernel.org>
8  */
9 
10 #include <linux/etherdevice.h>
11 #include <linux/module.h>
12 #include "mt7615.h"
13 #include "mcu.h"
14 
15 static bool mt7615_dev_running(struct mt7615_dev *dev)
16 {
17 	struct mt7615_phy *phy;
18 
19 	if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state))
20 		return true;
21 
22 	phy = mt7615_ext_phy(dev);
23 
24 	return phy && test_bit(MT76_STATE_RUNNING, &phy->mt76->state);
25 }
26 
27 static void mt7615_free_pending_tx_skbs(struct mt7615_dev *dev,
28 					struct mt7615_sta *msta)
29 {
30 	int i;
31 
32 	spin_lock_bh(&dev->pm.txq_lock);
33 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
34 		if (msta && dev->pm.tx_q[i].msta != msta)
35 			continue;
36 
37 		dev_kfree_skb(dev->pm.tx_q[i].skb);
38 		dev->pm.tx_q[i].skb = NULL;
39 	}
40 	spin_unlock_bh(&dev->pm.txq_lock);
41 }
42 
43 static int mt7615_start(struct ieee80211_hw *hw)
44 {
45 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
46 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
47 	bool running;
48 
49 	if (!mt7615_wait_for_mcu_init(dev))
50 		return -EIO;
51 
52 	mt7615_mutex_acquire(dev);
53 
54 	running = mt7615_dev_running(dev);
55 
56 	if (!running) {
57 		mt7615_mcu_set_pm(dev, 0, 0);
58 		mt7615_mcu_set_mac_enable(dev, 0, true);
59 		mt7615_mac_enable_nf(dev, 0);
60 	}
61 
62 	if (phy != &dev->phy) {
63 		mt7615_mcu_set_pm(dev, 1, 0);
64 		mt7615_mcu_set_mac_enable(dev, 1, true);
65 		mt7615_mac_enable_nf(dev, 1);
66 	}
67 
68 	mt7615_mcu_set_channel_domain(phy);
69 	mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD_SET_RX_PATH);
70 
71 	set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
72 
73 	ieee80211_queue_delayed_work(hw, &phy->mac_work,
74 				     MT7615_WATCHDOG_TIME);
75 
76 	if (!running)
77 		mt7615_mac_reset_counters(dev);
78 
79 	mt7615_mutex_release(dev);
80 
81 	return 0;
82 }
83 
84 static void mt7615_stop(struct ieee80211_hw *hw)
85 {
86 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
87 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
88 
89 	cancel_delayed_work_sync(&phy->mac_work);
90 	del_timer_sync(&phy->roc_timer);
91 	cancel_work_sync(&phy->roc_work);
92 
93 	cancel_delayed_work_sync(&dev->pm.ps_work);
94 	cancel_work_sync(&dev->pm.wake_work);
95 
96 	mt7615_free_pending_tx_skbs(dev, NULL);
97 
98 	mt7615_mutex_acquire(dev);
99 
100 	mt76_testmode_reset(&dev->mt76, true);
101 
102 	clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
103 	cancel_delayed_work_sync(&phy->scan_work);
104 
105 	if (phy != &dev->phy) {
106 		mt7615_mcu_set_pm(dev, 1, 1);
107 		mt7615_mcu_set_mac_enable(dev, 1, false);
108 	}
109 
110 	if (!mt7615_dev_running(dev)) {
111 		mt7615_mcu_set_pm(dev, 0, 1);
112 		mt7615_mcu_set_mac_enable(dev, 0, false);
113 	}
114 
115 	mt7615_mutex_release(dev);
116 }
117 
118 static int get_omac_idx(enum nl80211_iftype type, u32 mask)
119 {
120 	int i;
121 
122 	switch (type) {
123 	case NL80211_IFTYPE_MONITOR:
124 	case NL80211_IFTYPE_AP:
125 	case NL80211_IFTYPE_MESH_POINT:
126 	case NL80211_IFTYPE_ADHOC:
127 		/* ap use hw bssid 0 and ext bssid */
128 		if (~mask & BIT(HW_BSSID_0))
129 			return HW_BSSID_0;
130 
131 		for (i = EXT_BSSID_1; i < EXT_BSSID_END; i++)
132 			if (~mask & BIT(i))
133 				return i;
134 
135 		break;
136 	case NL80211_IFTYPE_STATION:
137 		/* sta use hw bssid other than 0 */
138 		for (i = HW_BSSID_1; i < HW_BSSID_MAX; i++)
139 			if (~mask & BIT(i))
140 				return i;
141 
142 		break;
143 	default:
144 		WARN_ON(1);
145 		break;
146 	}
147 
148 	return -1;
149 }
150 
151 static int mt7615_add_interface(struct ieee80211_hw *hw,
152 				struct ieee80211_vif *vif)
153 {
154 	struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
155 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
156 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
157 	struct mt76_txq *mtxq;
158 	bool ext_phy = phy != &dev->phy;
159 	int idx, ret = 0;
160 
161 	mt7615_mutex_acquire(dev);
162 
163 	mt76_testmode_reset(&dev->mt76, true);
164 
165 	if (vif->type == NL80211_IFTYPE_MONITOR &&
166 	    is_zero_ether_addr(vif->addr))
167 		phy->monitor_vif = vif;
168 
169 	mvif->idx = ffs(~dev->mphy.vif_mask) - 1;
170 	if (mvif->idx >= MT7615_MAX_INTERFACES) {
171 		ret = -ENOSPC;
172 		goto out;
173 	}
174 
175 	idx = get_omac_idx(vif->type, dev->omac_mask);
176 	if (idx < 0) {
177 		ret = -ENOSPC;
178 		goto out;
179 	}
180 	mvif->omac_idx = idx;
181 
182 	mvif->band_idx = ext_phy;
183 	if (mt7615_ext_phy(dev))
184 		mvif->wmm_idx = ext_phy * (MT7615_MAX_WMM_SETS / 2) +
185 				mvif->idx % (MT7615_MAX_WMM_SETS / 2);
186 	else
187 		mvif->wmm_idx = mvif->idx % MT7615_MAX_WMM_SETS;
188 
189 	dev->mphy.vif_mask |= BIT(mvif->idx);
190 	dev->omac_mask |= BIT(mvif->omac_idx);
191 	phy->omac_mask |= BIT(mvif->omac_idx);
192 
193 	mt7615_mcu_set_dbdc(dev);
194 
195 	idx = MT7615_WTBL_RESERVED - mvif->idx;
196 
197 	INIT_LIST_HEAD(&mvif->sta.poll_list);
198 	mvif->sta.wcid.idx = idx;
199 	mvif->sta.wcid.ext_phy = mvif->band_idx;
200 	mvif->sta.wcid.hw_key_idx = -1;
201 	mt7615_mac_wtbl_update(dev, idx,
202 			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
203 
204 	rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid);
205 	if (vif->txq) {
206 		mtxq = (struct mt76_txq *)vif->txq->drv_priv;
207 		mtxq->wcid = &mvif->sta.wcid;
208 		mt76_txq_init(&dev->mt76, vif->txq);
209 	}
210 
211 	ret = mt7615_mcu_add_dev_info(dev, vif, true);
212 	if (ret)
213 		goto out;
214 
215 	if (dev->pm.enable) {
216 		ret = mt7615_mcu_set_bss_pm(dev, vif, true);
217 		if (ret)
218 			goto out;
219 
220 		vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
221 		mt76_set(dev, MT_WF_RFCR(ext_phy),
222 			 MT_WF_RFCR_DROP_OTHER_BEACON);
223 	}
224 out:
225 	mt7615_mutex_release(dev);
226 
227 	return ret;
228 }
229 
230 static void mt7615_remove_interface(struct ieee80211_hw *hw,
231 				    struct ieee80211_vif *vif)
232 {
233 	struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
234 	struct mt7615_sta *msta = &mvif->sta;
235 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
236 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
237 	int idx = msta->wcid.idx;
238 
239 	/* TODO: disable beacon for the bss */
240 
241 	mt7615_mutex_acquire(dev);
242 
243 	mt76_testmode_reset(&dev->mt76, true);
244 	if (vif == phy->monitor_vif)
245 	    phy->monitor_vif = NULL;
246 
247 	mt7615_free_pending_tx_skbs(dev, msta);
248 
249 	if (dev->pm.enable) {
250 		bool ext_phy = phy != &dev->phy;
251 
252 		mt7615_mcu_set_bss_pm(dev, vif, false);
253 		mt76_clear(dev, MT_WF_RFCR(ext_phy),
254 			   MT_WF_RFCR_DROP_OTHER_BEACON);
255 	}
256 	mt7615_mcu_add_dev_info(dev, vif, false);
257 
258 	rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
259 	if (vif->txq)
260 		mt76_txq_remove(&dev->mt76, vif->txq);
261 
262 	dev->mphy.vif_mask &= ~BIT(mvif->idx);
263 	dev->omac_mask &= ~BIT(mvif->omac_idx);
264 	phy->omac_mask &= ~BIT(mvif->omac_idx);
265 
266 	mt7615_mutex_release(dev);
267 
268 	spin_lock_bh(&dev->sta_poll_lock);
269 	if (!list_empty(&msta->poll_list))
270 		list_del_init(&msta->poll_list);
271 	spin_unlock_bh(&dev->sta_poll_lock);
272 }
273 
274 static void mt7615_init_dfs_state(struct mt7615_phy *phy)
275 {
276 	struct mt76_phy *mphy = phy->mt76;
277 	struct ieee80211_hw *hw = mphy->hw;
278 	struct cfg80211_chan_def *chandef = &hw->conf.chandef;
279 
280 	if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
281 		return;
282 
283 	if (!(chandef->chan->flags & IEEE80211_CHAN_RADAR))
284 		return;
285 
286 	if (mphy->chandef.chan->center_freq == chandef->chan->center_freq &&
287 	    mphy->chandef.width == chandef->width)
288 		return;
289 
290 	phy->dfs_state = -1;
291 }
292 
293 int mt7615_set_channel(struct mt7615_phy *phy)
294 {
295 	struct mt7615_dev *dev = phy->dev;
296 	bool ext_phy = phy != &dev->phy;
297 	int ret;
298 
299 	cancel_delayed_work_sync(&phy->mac_work);
300 
301 	mt7615_mutex_acquire(dev);
302 
303 	set_bit(MT76_RESET, &phy->mt76->state);
304 
305 	mt7615_init_dfs_state(phy);
306 	mt76_set_channel(phy->mt76);
307 
308 	if (is_mt7615(&dev->mt76) && dev->flash_eeprom) {
309 		mt7615_mcu_apply_rx_dcoc(phy);
310 		mt7615_mcu_apply_tx_dpd(phy);
311 	}
312 
313 	ret = mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD_CHANNEL_SWITCH);
314 	if (ret)
315 		goto out;
316 
317 	mt7615_mac_set_timing(phy);
318 	ret = mt7615_dfs_init_radar_detector(phy);
319 	mt7615_mac_cca_stats_reset(phy);
320 	mt7615_mcu_set_sku_en(phy, !mt76_testmode_enabled(&dev->mt76));
321 
322 	mt7615_mac_reset_counters(dev);
323 	phy->noise = 0;
324 	phy->chfreq = mt76_rr(dev, MT_CHFREQ(ext_phy));
325 
326 out:
327 	clear_bit(MT76_RESET, &phy->mt76->state);
328 
329 	mt7615_mutex_release(dev);
330 
331 	mt76_txq_schedule_all(phy->mt76);
332 
333 	if (!mt76_testmode_enabled(&dev->mt76))
334 		ieee80211_queue_delayed_work(phy->mt76->hw, &phy->mac_work,
335 					     MT7615_WATCHDOG_TIME);
336 
337 	return ret;
338 }
339 
340 static int
341 mt7615_queue_key_update(struct mt7615_dev *dev, enum set_key_cmd cmd,
342 			struct mt7615_sta *msta,
343 			struct ieee80211_key_conf *key)
344 {
345 	struct mt7615_wtbl_desc *wd;
346 
347 	wd = kzalloc(sizeof(*wd), GFP_KERNEL);
348 	if (!wd)
349 		return -ENOMEM;
350 
351 	wd->type = MT7615_WTBL_KEY_DESC;
352 	wd->sta = msta;
353 
354 	wd->key.key = kmemdup(key->key, key->keylen, GFP_KERNEL);
355 	if (!wd->key.key) {
356 		kfree(wd);
357 		return -ENOMEM;
358 	}
359 	wd->key.cipher = key->cipher;
360 	wd->key.keyidx = key->keyidx;
361 	wd->key.keylen = key->keylen;
362 	wd->key.cmd = cmd;
363 
364 	list_add_tail(&wd->node, &dev->wd_head);
365 	queue_work(dev->mt76.wq, &dev->wtbl_work);
366 
367 	return 0;
368 }
369 
370 static int mt7615_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
371 			  struct ieee80211_vif *vif, struct ieee80211_sta *sta,
372 			  struct ieee80211_key_conf *key)
373 {
374 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
375 	struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
376 	struct mt7615_sta *msta = sta ? (struct mt7615_sta *)sta->drv_priv :
377 				  &mvif->sta;
378 	struct mt76_wcid *wcid = &msta->wcid;
379 	int idx = key->keyidx, err;
380 
381 	/* The hardware does not support per-STA RX GTK, fallback
382 	 * to software mode for these.
383 	 */
384 	if ((vif->type == NL80211_IFTYPE_ADHOC ||
385 	     vif->type == NL80211_IFTYPE_MESH_POINT) &&
386 	    (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
387 	     key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
388 	    !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
389 		return -EOPNOTSUPP;
390 
391 	/* fall back to sw encryption for unsupported ciphers */
392 	switch (key->cipher) {
393 	case WLAN_CIPHER_SUITE_AES_CMAC:
394 		key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
395 		break;
396 	case WLAN_CIPHER_SUITE_WEP40:
397 	case WLAN_CIPHER_SUITE_WEP104:
398 	case WLAN_CIPHER_SUITE_TKIP:
399 	case WLAN_CIPHER_SUITE_CCMP:
400 	case WLAN_CIPHER_SUITE_CCMP_256:
401 	case WLAN_CIPHER_SUITE_GCMP:
402 	case WLAN_CIPHER_SUITE_GCMP_256:
403 	case WLAN_CIPHER_SUITE_SMS4:
404 		break;
405 	default:
406 		return -EOPNOTSUPP;
407 	}
408 
409 	mt7615_mutex_acquire(dev);
410 
411 	if (cmd == SET_KEY) {
412 		key->hw_key_idx = wcid->idx;
413 		wcid->hw_key_idx = idx;
414 	} else if (idx == wcid->hw_key_idx) {
415 		wcid->hw_key_idx = -1;
416 	}
417 	mt76_wcid_key_setup(&dev->mt76, wcid,
418 			    cmd == SET_KEY ? key : NULL);
419 
420 	if (mt76_is_mmio(&dev->mt76))
421 		err = mt7615_mac_wtbl_set_key(dev, wcid, key, cmd);
422 	else
423 		err = mt7615_queue_key_update(dev, cmd, msta, key);
424 
425 	mt7615_mutex_release(dev);
426 
427 	return err;
428 }
429 
430 static int mt7615_config(struct ieee80211_hw *hw, u32 changed)
431 {
432 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
433 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
434 	bool band = phy != &dev->phy;
435 	int ret = 0;
436 
437 	if (changed & (IEEE80211_CONF_CHANGE_CHANNEL |
438 		       IEEE80211_CONF_CHANGE_POWER)) {
439 #ifdef CONFIG_NL80211_TESTMODE
440 		if (dev->mt76.test.state != MT76_TM_STATE_OFF) {
441 			mt7615_mutex_acquire(dev);
442 			mt76_testmode_reset(&dev->mt76, false);
443 			mt7615_mutex_release(dev);
444 		}
445 #endif
446 		ieee80211_stop_queues(hw);
447 		ret = mt7615_set_channel(phy);
448 		ieee80211_wake_queues(hw);
449 	}
450 
451 	mt7615_mutex_acquire(dev);
452 
453 	if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
454 		mt76_testmode_reset(&dev->mt76, true);
455 
456 		if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
457 			phy->rxfilter |= MT_WF_RFCR_DROP_OTHER_UC;
458 		else
459 			phy->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_UC;
460 
461 		mt76_wr(dev, MT_WF_RFCR(band), phy->rxfilter);
462 	}
463 
464 	mt7615_mutex_release(dev);
465 
466 	return ret;
467 }
468 
469 static int
470 mt7615_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
471 	       const struct ieee80211_tx_queue_params *params)
472 {
473 	struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
474 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
475 	int err;
476 
477 	mt7615_mutex_acquire(dev);
478 
479 	queue = mt7615_lmac_mapping(dev, queue);
480 	queue += mvif->wmm_idx * MT7615_MAX_WMM_SETS;
481 	err = mt7615_mcu_set_wmm(dev, queue, params);
482 
483 	mt7615_mutex_release(dev);
484 
485 	return err;
486 }
487 
488 static void mt7615_configure_filter(struct ieee80211_hw *hw,
489 				    unsigned int changed_flags,
490 				    unsigned int *total_flags,
491 				    u64 multicast)
492 {
493 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
494 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
495 	bool band = phy != &dev->phy;
496 
497 	u32 ctl_flags = MT_WF_RFCR1_DROP_ACK |
498 			MT_WF_RFCR1_DROP_BF_POLL |
499 			MT_WF_RFCR1_DROP_BA |
500 			MT_WF_RFCR1_DROP_CFEND |
501 			MT_WF_RFCR1_DROP_CFACK;
502 	u32 flags = 0;
503 
504 	mt7615_mutex_acquire(dev);
505 
506 #define MT76_FILTER(_flag, _hw) do { \
507 		flags |= *total_flags & FIF_##_flag;			\
508 		phy->rxfilter &= ~(_hw);				\
509 		if (!mt76_testmode_enabled(&dev->mt76))			\
510 			phy->rxfilter |= !(flags & FIF_##_flag) * (_hw);\
511 	} while (0)
512 
513 	phy->rxfilter &= ~(MT_WF_RFCR_DROP_OTHER_BSS |
514 			   MT_WF_RFCR_DROP_OTHER_BEACON |
515 			   MT_WF_RFCR_DROP_FRAME_REPORT |
516 			   MT_WF_RFCR_DROP_PROBEREQ |
517 			   MT_WF_RFCR_DROP_MCAST_FILTERED |
518 			   MT_WF_RFCR_DROP_MCAST |
519 			   MT_WF_RFCR_DROP_BCAST |
520 			   MT_WF_RFCR_DROP_DUPLICATE |
521 			   MT_WF_RFCR_DROP_A2_BSSID |
522 			   MT_WF_RFCR_DROP_UNWANTED_CTL |
523 			   MT_WF_RFCR_DROP_STBC_MULTI);
524 
525 	MT76_FILTER(OTHER_BSS, MT_WF_RFCR_DROP_OTHER_TIM |
526 			       MT_WF_RFCR_DROP_A3_MAC |
527 			       MT_WF_RFCR_DROP_A3_BSSID);
528 
529 	MT76_FILTER(FCSFAIL, MT_WF_RFCR_DROP_FCSFAIL);
530 
531 	MT76_FILTER(CONTROL, MT_WF_RFCR_DROP_CTS |
532 			     MT_WF_RFCR_DROP_RTS |
533 			     MT_WF_RFCR_DROP_CTL_RSV |
534 			     MT_WF_RFCR_DROP_NDPA);
535 
536 	*total_flags = flags;
537 	mt76_wr(dev, MT_WF_RFCR(band), phy->rxfilter);
538 
539 	if (*total_flags & FIF_CONTROL)
540 		mt76_clear(dev, MT_WF_RFCR1(band), ctl_flags);
541 	else
542 		mt76_set(dev, MT_WF_RFCR1(band), ctl_flags);
543 
544 	mt7615_mutex_release(dev);
545 }
546 
547 static void mt7615_bss_info_changed(struct ieee80211_hw *hw,
548 				    struct ieee80211_vif *vif,
549 				    struct ieee80211_bss_conf *info,
550 				    u32 changed)
551 {
552 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
553 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
554 
555 	mt7615_mutex_acquire(dev);
556 
557 	if (changed & BSS_CHANGED_ERP_SLOT) {
558 		int slottime = info->use_short_slot ? 9 : 20;
559 
560 		if (slottime != phy->slottime) {
561 			phy->slottime = slottime;
562 			mt7615_mac_set_timing(phy);
563 		}
564 	}
565 
566 	if (changed & BSS_CHANGED_BEACON_ENABLED) {
567 		mt7615_mcu_add_bss_info(phy, vif, NULL, info->enable_beacon);
568 		mt7615_mcu_sta_add(dev, vif, NULL, info->enable_beacon);
569 
570 		if (vif->p2p && info->enable_beacon)
571 			mt7615_mcu_set_p2p_oppps(hw, vif);
572 	}
573 
574 	if (changed & (BSS_CHANGED_BEACON |
575 		       BSS_CHANGED_BEACON_ENABLED))
576 		mt7615_mcu_add_beacon(dev, hw, vif, info->enable_beacon);
577 
578 	if (changed & BSS_CHANGED_PS)
579 		mt7615_mcu_set_vif_ps(dev, vif);
580 
581 	if (changed & BSS_CHANGED_ARP_FILTER)
582 		mt7615_mcu_update_arp_filter(hw, vif, info);
583 
584 	mt7615_mutex_release(dev);
585 }
586 
587 static void
588 mt7615_channel_switch_beacon(struct ieee80211_hw *hw,
589 			     struct ieee80211_vif *vif,
590 			     struct cfg80211_chan_def *chandef)
591 {
592 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
593 
594 	mt7615_mutex_acquire(dev);
595 	mt7615_mcu_add_beacon(dev, hw, vif, true);
596 	mt7615_mutex_release(dev);
597 }
598 
599 int mt7615_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
600 		       struct ieee80211_sta *sta)
601 {
602 	struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
603 	struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv;
604 	struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
605 	int idx, err;
606 
607 	idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7615_WTBL_STA - 1);
608 	if (idx < 0)
609 		return -ENOSPC;
610 
611 	INIT_LIST_HEAD(&msta->poll_list);
612 	msta->vif = mvif;
613 	msta->wcid.sta = 1;
614 	msta->wcid.idx = idx;
615 	msta->wcid.ext_phy = mvif->band_idx;
616 
617 	err = mt7615_pm_wake(dev);
618 	if (err)
619 		return err;
620 
621 	if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) {
622 		struct mt7615_phy *phy;
623 
624 		phy = mvif->band_idx ? mt7615_ext_phy(dev) : &dev->phy;
625 		mt7615_mcu_add_bss_info(phy, vif, sta, true);
626 	}
627 	mt7615_mac_wtbl_update(dev, idx,
628 			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
629 	mt7615_mcu_sta_add(dev, vif, sta, true);
630 
631 	mt7615_pm_power_save_sched(dev);
632 
633 	return 0;
634 }
635 EXPORT_SYMBOL_GPL(mt7615_mac_sta_add);
636 
637 void mt7615_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
638 			   struct ieee80211_sta *sta)
639 {
640 	struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
641 	struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv;
642 
643 	mt7615_free_pending_tx_skbs(dev, msta);
644 	mt7615_pm_wake(dev);
645 
646 	mt7615_mcu_sta_add(dev, vif, sta, false);
647 	mt7615_mac_wtbl_update(dev, msta->wcid.idx,
648 			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
649 	if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) {
650 		struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
651 		struct mt7615_phy *phy;
652 
653 		phy = mvif->band_idx ? mt7615_ext_phy(dev) : &dev->phy;
654 		mt7615_mcu_add_bss_info(phy, vif, sta, false);
655 	}
656 
657 	spin_lock_bh(&dev->sta_poll_lock);
658 	if (!list_empty(&msta->poll_list))
659 		list_del_init(&msta->poll_list);
660 	spin_unlock_bh(&dev->sta_poll_lock);
661 
662 	mt7615_pm_power_save_sched(dev);
663 }
664 EXPORT_SYMBOL_GPL(mt7615_mac_sta_remove);
665 
666 static void mt7615_sta_rate_tbl_update(struct ieee80211_hw *hw,
667 				       struct ieee80211_vif *vif,
668 				       struct ieee80211_sta *sta)
669 {
670 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
671 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
672 	struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv;
673 	struct ieee80211_sta_rates *sta_rates = rcu_dereference(sta->rates);
674 	int i;
675 
676 	spin_lock_bh(&dev->mt76.lock);
677 	for (i = 0; i < ARRAY_SIZE(msta->rates); i++) {
678 		msta->rates[i].idx = sta_rates->rate[i].idx;
679 		msta->rates[i].count = sta_rates->rate[i].count;
680 		msta->rates[i].flags = sta_rates->rate[i].flags;
681 
682 		if (msta->rates[i].idx < 0 || !msta->rates[i].count)
683 			break;
684 	}
685 	msta->n_rates = i;
686 	if (!test_bit(MT76_STATE_PM, &phy->mt76->state))
687 		mt7615_mac_set_rates(phy, msta, NULL, msta->rates);
688 	spin_unlock_bh(&dev->mt76.lock);
689 }
690 
691 static void
692 mt7615_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
693 {
694 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
695 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
696 	struct mt76_phy *mphy = phy->mt76;
697 
698 	if (!test_bit(MT76_STATE_RUNNING, &mphy->state))
699 		return;
700 
701 	if (test_bit(MT76_STATE_PM, &mphy->state)) {
702 		queue_work(dev->mt76.wq, &dev->pm.wake_work);
703 		return;
704 	}
705 
706 	tasklet_schedule(&dev->mt76.tx_tasklet);
707 }
708 
709 static void mt7615_tx(struct ieee80211_hw *hw,
710 		      struct ieee80211_tx_control *control,
711 		      struct sk_buff *skb)
712 {
713 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
714 	struct mt76_phy *mphy = hw->priv;
715 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
716 	struct ieee80211_vif *vif = info->control.vif;
717 	struct mt76_wcid *wcid = &dev->mt76.global_wcid;
718 	struct mt7615_sta *msta = NULL;
719 	int qid;
720 
721 	if (control->sta) {
722 		msta = (struct mt7615_sta *)control->sta->drv_priv;
723 		wcid = &msta->wcid;
724 	}
725 
726 	if (vif && !control->sta) {
727 		struct mt7615_vif *mvif;
728 
729 		mvif = (struct mt7615_vif *)vif->drv_priv;
730 		msta = &mvif->sta;
731 		wcid = &msta->wcid;
732 	}
733 
734 	if (!test_bit(MT76_STATE_PM, &mphy->state)) {
735 		mt76_tx(mphy, control->sta, wcid, skb);
736 		return;
737 	}
738 
739 	qid = skb_get_queue_mapping(skb);
740 	if (qid >= MT_TXQ_PSD) {
741 		qid = IEEE80211_AC_BE;
742 		skb_set_queue_mapping(skb, qid);
743 	}
744 
745 	spin_lock_bh(&dev->pm.txq_lock);
746 	if (!dev->pm.tx_q[qid].skb) {
747 		ieee80211_stop_queues(hw);
748 		dev->pm.tx_q[qid].msta = msta;
749 		dev->pm.tx_q[qid].skb = skb;
750 		queue_work(dev->mt76.wq, &dev->pm.wake_work);
751 	} else {
752 		dev_kfree_skb(skb);
753 	}
754 	spin_unlock_bh(&dev->pm.txq_lock);
755 }
756 
757 static int mt7615_set_rts_threshold(struct ieee80211_hw *hw, u32 val)
758 {
759 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
760 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
761 
762 	mt7615_mutex_acquire(dev);
763 	mt7615_mcu_set_rts_thresh(phy, val);
764 	mt7615_mutex_release(dev);
765 
766 	return 0;
767 }
768 
769 static int
770 mt7615_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
771 		    struct ieee80211_ampdu_params *params)
772 {
773 	enum ieee80211_ampdu_mlme_action action = params->action;
774 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
775 	struct ieee80211_sta *sta = params->sta;
776 	struct ieee80211_txq *txq = sta->txq[params->tid];
777 	struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv;
778 	u16 tid = params->tid;
779 	u16 ssn = params->ssn;
780 	struct mt76_txq *mtxq;
781 	int ret = 0;
782 
783 	if (!txq)
784 		return -EINVAL;
785 
786 	mtxq = (struct mt76_txq *)txq->drv_priv;
787 
788 	mt7615_mutex_acquire(dev);
789 
790 	switch (action) {
791 	case IEEE80211_AMPDU_RX_START:
792 		mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, ssn,
793 				   params->buf_size);
794 		mt7615_mcu_add_rx_ba(dev, params, true);
795 		break;
796 	case IEEE80211_AMPDU_RX_STOP:
797 		mt76_rx_aggr_stop(&dev->mt76, &msta->wcid, tid);
798 		mt7615_mcu_add_rx_ba(dev, params, false);
799 		break;
800 	case IEEE80211_AMPDU_TX_OPERATIONAL:
801 		mtxq->aggr = true;
802 		mtxq->send_bar = false;
803 		mt7615_mcu_add_tx_ba(dev, params, true);
804 		ssn = mt7615_mac_get_sta_tid_sn(dev, msta->wcid.idx, tid);
805 		ieee80211_send_bar(vif, sta->addr, tid,
806 				   IEEE80211_SN_TO_SEQ(ssn));
807 		break;
808 	case IEEE80211_AMPDU_TX_STOP_FLUSH:
809 	case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
810 		mtxq->aggr = false;
811 		mt7615_mcu_add_tx_ba(dev, params, false);
812 		break;
813 	case IEEE80211_AMPDU_TX_START:
814 		ssn = mt7615_mac_get_sta_tid_sn(dev, msta->wcid.idx, tid);
815 		params->ssn = ssn;
816 		mtxq->agg_ssn = IEEE80211_SN_TO_SEQ(ssn);
817 		ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;
818 		break;
819 	case IEEE80211_AMPDU_TX_STOP_CONT:
820 		mtxq->aggr = false;
821 		mt7615_mcu_add_tx_ba(dev, params, false);
822 		ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
823 		break;
824 	}
825 	mt7615_mutex_release(dev);
826 
827 	return ret;
828 }
829 
830 static int
831 mt7615_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
832 	       struct ieee80211_sta *sta)
833 {
834     return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NOTEXIST,
835 			  IEEE80211_STA_NONE);
836 }
837 
838 static int
839 mt7615_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
840 		  struct ieee80211_sta *sta)
841 {
842     return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NONE,
843 			  IEEE80211_STA_NOTEXIST);
844 }
845 
846 static int
847 mt7615_get_stats(struct ieee80211_hw *hw,
848 		 struct ieee80211_low_level_stats *stats)
849 {
850 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
851 	struct mib_stats *mib = &phy->mib;
852 
853 	stats->dot11RTSSuccessCount = mib->rts_cnt;
854 	stats->dot11RTSFailureCount = mib->rts_retries_cnt;
855 	stats->dot11FCSErrorCount = mib->fcs_err_cnt;
856 	stats->dot11ACKFailureCount = mib->ack_fail_cnt;
857 
858 	return 0;
859 }
860 
861 static u64
862 mt7615_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
863 {
864 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
865 	union {
866 		u64 t64;
867 		u32 t32[2];
868 	} tsf;
869 
870 	mt7615_mutex_acquire(dev);
871 
872 	mt76_set(dev, MT_LPON_T0CR, MT_LPON_T0CR_MODE); /* TSF read */
873 	tsf.t32[0] = mt76_rr(dev, MT_LPON_UTTR0);
874 	tsf.t32[1] = mt76_rr(dev, MT_LPON_UTTR1);
875 
876 	mt7615_mutex_release(dev);
877 
878 	return tsf.t64;
879 }
880 
881 static void
882 mt7615_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
883 	       u64 timestamp)
884 {
885 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
886 	union {
887 		u64 t64;
888 		u32 t32[2];
889 	} tsf = { .t64 = timestamp, };
890 
891 	mt7615_mutex_acquire(dev);
892 
893 	mt76_wr(dev, MT_LPON_UTTR0, tsf.t32[0]);
894 	mt76_wr(dev, MT_LPON_UTTR1, tsf.t32[1]);
895 	/* TSF software overwrite */
896 	mt76_set(dev, MT_LPON_T0CR, MT_LPON_T0CR_WRITE);
897 
898 	mt7615_mutex_release(dev);
899 }
900 
901 static void
902 mt7615_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class)
903 {
904 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
905 	struct mt7615_dev *dev = phy->dev;
906 
907 	mt7615_mutex_acquire(dev);
908 	phy->coverage_class = max_t(s16, coverage_class, 0);
909 	mt7615_mac_set_timing(phy);
910 	mt7615_mutex_release(dev);
911 }
912 
913 static int
914 mt7615_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
915 {
916 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
917 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
918 	int max_nss = hweight8(hw->wiphy->available_antennas_tx);
919 	bool ext_phy = phy != &dev->phy;
920 
921 	if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss)
922 		return -EINVAL;
923 
924 	if ((BIT(hweight8(tx_ant)) - 1) != tx_ant)
925 		tx_ant = BIT(ffs(tx_ant) - 1) - 1;
926 
927 	mt7615_mutex_acquire(dev);
928 
929 	phy->mt76->antenna_mask = tx_ant;
930 	if (ext_phy) {
931 		if (dev->chainmask == 0xf)
932 			tx_ant <<= 2;
933 		else
934 			tx_ant <<= 1;
935 	}
936 	phy->chainmask = tx_ant;
937 
938 	mt76_set_stream_caps(phy->mt76, true);
939 
940 	mt7615_mutex_release(dev);
941 
942 	return 0;
943 }
944 
945 static void mt7615_roc_iter(void *priv, u8 *mac,
946 			    struct ieee80211_vif *vif)
947 {
948 	struct mt7615_phy *phy = priv;
949 
950 	mt7615_mcu_set_roc(phy, vif, NULL, 0);
951 }
952 
953 void mt7615_roc_work(struct work_struct *work)
954 {
955 	struct mt7615_phy *phy;
956 
957 	phy = (struct mt7615_phy *)container_of(work, struct mt7615_phy,
958 						roc_work);
959 
960 	if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
961 		return;
962 
963 	mt7615_mutex_acquire(phy->dev);
964 	ieee80211_iterate_active_interfaces(phy->mt76->hw,
965 					    IEEE80211_IFACE_ITER_RESUME_ALL,
966 					    mt7615_roc_iter, phy);
967 	mt7615_mutex_release(phy->dev);
968 	ieee80211_remain_on_channel_expired(phy->mt76->hw);
969 }
970 
971 void mt7615_roc_timer(struct timer_list *timer)
972 {
973 	struct mt7615_phy *phy = from_timer(phy, timer, roc_timer);
974 
975 	ieee80211_queue_work(phy->mt76->hw, &phy->roc_work);
976 }
977 
978 void mt7615_scan_work(struct work_struct *work)
979 {
980 	struct mt7615_phy *phy;
981 
982 	phy = (struct mt7615_phy *)container_of(work, struct mt7615_phy,
983 						scan_work.work);
984 
985 	while (true) {
986 		struct mt7615_mcu_rxd *rxd;
987 		struct sk_buff *skb;
988 
989 		spin_lock_bh(&phy->dev->mt76.lock);
990 		skb = __skb_dequeue(&phy->scan_event_list);
991 		spin_unlock_bh(&phy->dev->mt76.lock);
992 
993 		if (!skb)
994 			break;
995 
996 		rxd = (struct mt7615_mcu_rxd *)skb->data;
997 		if (rxd->eid == MCU_EVENT_SCHED_SCAN_DONE) {
998 			ieee80211_sched_scan_results(phy->mt76->hw);
999 		} else if (test_and_clear_bit(MT76_HW_SCANNING,
1000 					      &phy->mt76->state)) {
1001 			struct cfg80211_scan_info info = {
1002 				.aborted = false,
1003 			};
1004 
1005 			ieee80211_scan_completed(phy->mt76->hw, &info);
1006 		}
1007 		dev_kfree_skb(skb);
1008 	}
1009 }
1010 
1011 static int
1012 mt7615_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1013 	       struct ieee80211_scan_request *req)
1014 {
1015 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
1016 	struct mt76_phy *mphy = hw->priv;
1017 	int err;
1018 
1019 	mt7615_mutex_acquire(dev);
1020 	err = mt7615_mcu_hw_scan(mphy->priv, vif, req);
1021 	mt7615_mutex_release(dev);
1022 
1023 	return err;
1024 }
1025 
1026 static void
1027 mt7615_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1028 {
1029 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
1030 	struct mt76_phy *mphy = hw->priv;
1031 
1032 	mt7615_mutex_acquire(dev);
1033 	mt7615_mcu_cancel_hw_scan(mphy->priv, vif);
1034 	mt7615_mutex_release(dev);
1035 }
1036 
1037 static int
1038 mt7615_start_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1039 			struct cfg80211_sched_scan_request *req,
1040 			struct ieee80211_scan_ies *ies)
1041 {
1042 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
1043 	struct mt76_phy *mphy = hw->priv;
1044 	int err;
1045 
1046 	mt7615_mutex_acquire(dev);
1047 
1048 	err = mt7615_mcu_sched_scan_req(mphy->priv, vif, req);
1049 	if (err < 0)
1050 		goto out;
1051 
1052 	err = mt7615_mcu_sched_scan_enable(mphy->priv, vif, true);
1053 out:
1054 	mt7615_mutex_release(dev);
1055 
1056 	return err;
1057 }
1058 
1059 static int
1060 mt7615_stop_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1061 {
1062 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
1063 	struct mt76_phy *mphy = hw->priv;
1064 	int err;
1065 
1066 	mt7615_mutex_acquire(dev);
1067 	err = mt7615_mcu_sched_scan_enable(mphy->priv, vif, false);
1068 	mt7615_mutex_release(dev);
1069 
1070 	return err;
1071 }
1072 
1073 static int mt7615_remain_on_channel(struct ieee80211_hw *hw,
1074 				    struct ieee80211_vif *vif,
1075 				    struct ieee80211_channel *chan,
1076 				    int duration,
1077 				    enum ieee80211_roc_type type)
1078 {
1079 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
1080 	int err;
1081 
1082 	if (test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state))
1083 		return 0;
1084 
1085 	mt7615_mutex_acquire(phy->dev);
1086 
1087 	err = mt7615_mcu_set_roc(phy, vif, chan, duration);
1088 	if (err < 0) {
1089 		clear_bit(MT76_STATE_ROC, &phy->mt76->state);
1090 		goto out;
1091 	}
1092 
1093 	if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, HZ)) {
1094 		mt7615_mcu_set_roc(phy, vif, NULL, 0);
1095 		clear_bit(MT76_STATE_ROC, &phy->mt76->state);
1096 		err = -ETIMEDOUT;
1097 	}
1098 
1099 out:
1100 	mt7615_mutex_release(phy->dev);
1101 
1102 	return err;
1103 }
1104 
1105 static int mt7615_cancel_remain_on_channel(struct ieee80211_hw *hw,
1106 					   struct ieee80211_vif *vif)
1107 {
1108 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
1109 
1110 	if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
1111 		return 0;
1112 
1113 	del_timer_sync(&phy->roc_timer);
1114 	cancel_work_sync(&phy->roc_work);
1115 
1116 	mt7615_mutex_acquire(phy->dev);
1117 	mt7615_mcu_set_roc(phy, vif, NULL, 0);
1118 	mt7615_mutex_release(phy->dev);
1119 
1120 	return 0;
1121 }
1122 
1123 #ifdef CONFIG_PM
1124 static int mt7615_suspend(struct ieee80211_hw *hw,
1125 			  struct cfg80211_wowlan *wowlan)
1126 {
1127 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
1128 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
1129 	bool ext_phy = phy != &dev->phy;
1130 	int err = 0;
1131 
1132 	cancel_delayed_work_sync(&dev->pm.ps_work);
1133 	mt7615_free_pending_tx_skbs(dev, NULL);
1134 
1135 	mt7615_mutex_acquire(dev);
1136 
1137 	clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
1138 	cancel_delayed_work_sync(&phy->scan_work);
1139 	cancel_delayed_work_sync(&phy->mac_work);
1140 
1141 	mt76_set(dev, MT_WF_RFCR(ext_phy), MT_WF_RFCR_DROP_OTHER_BEACON);
1142 
1143 	set_bit(MT76_STATE_SUSPEND, &phy->mt76->state);
1144 	ieee80211_iterate_active_interfaces(hw,
1145 					    IEEE80211_IFACE_ITER_RESUME_ALL,
1146 					    mt7615_mcu_set_suspend_iter, phy);
1147 
1148 	if (!mt7615_dev_running(dev))
1149 		err = mt7615_mcu_set_hif_suspend(dev, true);
1150 
1151 	mt7615_mutex_release(dev);
1152 
1153 	return err;
1154 }
1155 
1156 static int mt7615_resume(struct ieee80211_hw *hw)
1157 {
1158 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
1159 	struct mt7615_phy *phy = mt7615_hw_phy(hw);
1160 	bool running, ext_phy = phy != &dev->phy;
1161 
1162 	mt7615_mutex_acquire(dev);
1163 
1164 	running = mt7615_dev_running(dev);
1165 	set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
1166 
1167 	if (!running) {
1168 		int err;
1169 
1170 		err = mt7615_mcu_set_hif_suspend(dev, false);
1171 		if (err < 0) {
1172 			mt7615_mutex_release(dev);
1173 			return err;
1174 		}
1175 	}
1176 
1177 	clear_bit(MT76_STATE_SUSPEND, &phy->mt76->state);
1178 	ieee80211_iterate_active_interfaces(hw,
1179 					    IEEE80211_IFACE_ITER_RESUME_ALL,
1180 					    mt7615_mcu_set_suspend_iter, phy);
1181 
1182 	ieee80211_queue_delayed_work(hw, &phy->mac_work,
1183 				     MT7615_WATCHDOG_TIME);
1184 	mt76_clear(dev, MT_WF_RFCR(ext_phy), MT_WF_RFCR_DROP_OTHER_BEACON);
1185 
1186 	mt7615_mutex_release(dev);
1187 
1188 	return 0;
1189 }
1190 
1191 static void mt7615_set_wakeup(struct ieee80211_hw *hw, bool enabled)
1192 {
1193 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
1194 	struct mt76_dev *mdev = &dev->mt76;
1195 
1196 	device_set_wakeup_enable(mdev->dev, enabled);
1197 }
1198 
1199 static void mt7615_set_rekey_data(struct ieee80211_hw *hw,
1200 				  struct ieee80211_vif *vif,
1201 				  struct cfg80211_gtk_rekey_data *data)
1202 {
1203 	struct mt7615_dev *dev = mt7615_hw_dev(hw);
1204 
1205 	mt7615_mutex_acquire(dev);
1206 	mt7615_mcu_update_gtk_rekey(hw, vif, data);
1207 	mt7615_mutex_release(dev);
1208 }
1209 #endif /* CONFIG_PM */
1210 
1211 const struct ieee80211_ops mt7615_ops = {
1212 	.tx = mt7615_tx,
1213 	.start = mt7615_start,
1214 	.stop = mt7615_stop,
1215 	.add_interface = mt7615_add_interface,
1216 	.remove_interface = mt7615_remove_interface,
1217 	.config = mt7615_config,
1218 	.conf_tx = mt7615_conf_tx,
1219 	.configure_filter = mt7615_configure_filter,
1220 	.bss_info_changed = mt7615_bss_info_changed,
1221 	.sta_add = mt7615_sta_add,
1222 	.sta_remove = mt7615_sta_remove,
1223 	.sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
1224 	.set_key = mt7615_set_key,
1225 	.ampdu_action = mt7615_ampdu_action,
1226 	.set_rts_threshold = mt7615_set_rts_threshold,
1227 	.wake_tx_queue = mt7615_wake_tx_queue,
1228 	.sta_rate_tbl_update = mt7615_sta_rate_tbl_update,
1229 	.sw_scan_start = mt76_sw_scan,
1230 	.sw_scan_complete = mt76_sw_scan_complete,
1231 	.release_buffered_frames = mt76_release_buffered_frames,
1232 	.get_txpower = mt76_get_txpower,
1233 	.channel_switch_beacon = mt7615_channel_switch_beacon,
1234 	.get_stats = mt7615_get_stats,
1235 	.get_tsf = mt7615_get_tsf,
1236 	.set_tsf = mt7615_set_tsf,
1237 	.get_survey = mt76_get_survey,
1238 	.get_antenna = mt76_get_antenna,
1239 	.set_antenna = mt7615_set_antenna,
1240 	.set_coverage_class = mt7615_set_coverage_class,
1241 	.hw_scan = mt7615_hw_scan,
1242 	.cancel_hw_scan = mt7615_cancel_hw_scan,
1243 	.sched_scan_start = mt7615_start_sched_scan,
1244 	.sched_scan_stop = mt7615_stop_sched_scan,
1245 	.remain_on_channel = mt7615_remain_on_channel,
1246 	.cancel_remain_on_channel = mt7615_cancel_remain_on_channel,
1247 	CFG80211_TESTMODE_CMD(mt76_testmode_cmd)
1248 	CFG80211_TESTMODE_DUMP(mt76_testmode_dump)
1249 #ifdef CONFIG_PM
1250 	.suspend = mt7615_suspend,
1251 	.resume = mt7615_resume,
1252 	.set_wakeup = mt7615_set_wakeup,
1253 	.set_rekey_data = mt7615_set_rekey_data,
1254 #endif /* CONFIG_PM */
1255 };
1256 EXPORT_SYMBOL_GPL(mt7615_ops);
1257 
1258 MODULE_LICENSE("Dual BSD/GPL");
1259