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
mt7615_dev_running(struct mt7615_dev * dev)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
mt7615_free_pending_tx_skbs(struct mt7615_dev * dev,struct mt7615_sta * msta)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
mt7615_start(struct ieee80211_hw * hw)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
mt7615_stop(struct ieee80211_hw * hw)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
get_omac_idx(enum nl80211_iftype type,u32 mask)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
mt7615_add_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)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 }
209
210 ret = mt7615_mcu_add_dev_info(dev, vif, true);
211 if (ret)
212 goto out;
213
214 if (dev->pm.enable) {
215 ret = mt7615_mcu_set_bss_pm(dev, vif, true);
216 if (ret)
217 goto out;
218
219 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
220 mt76_set(dev, MT_WF_RFCR(ext_phy),
221 MT_WF_RFCR_DROP_OTHER_BEACON);
222 }
223 out:
224 mt7615_mutex_release(dev);
225
226 return ret;
227 }
228
mt7615_remove_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)229 static void mt7615_remove_interface(struct ieee80211_hw *hw,
230 struct ieee80211_vif *vif)
231 {
232 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
233 struct mt7615_sta *msta = &mvif->sta;
234 struct mt7615_dev *dev = mt7615_hw_dev(hw);
235 struct mt7615_phy *phy = mt7615_hw_phy(hw);
236 int idx = msta->wcid.idx;
237
238 /* TODO: disable beacon for the bss */
239
240 mt7615_mutex_acquire(dev);
241
242 mt76_testmode_reset(&dev->mt76, true);
243 if (vif == phy->monitor_vif)
244 phy->monitor_vif = NULL;
245
246 mt7615_free_pending_tx_skbs(dev, msta);
247
248 if (dev->pm.enable) {
249 bool ext_phy = phy != &dev->phy;
250
251 mt7615_mcu_set_bss_pm(dev, vif, false);
252 mt76_clear(dev, MT_WF_RFCR(ext_phy),
253 MT_WF_RFCR_DROP_OTHER_BEACON);
254 }
255 mt7615_mcu_add_dev_info(dev, vif, false);
256
257 rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
258
259 dev->mphy.vif_mask &= ~BIT(mvif->idx);
260 dev->omac_mask &= ~BIT(mvif->omac_idx);
261 phy->omac_mask &= ~BIT(mvif->omac_idx);
262
263 mt7615_mutex_release(dev);
264
265 spin_lock_bh(&dev->sta_poll_lock);
266 if (!list_empty(&msta->poll_list))
267 list_del_init(&msta->poll_list);
268 spin_unlock_bh(&dev->sta_poll_lock);
269 }
270
mt7615_init_dfs_state(struct mt7615_phy * phy)271 static void mt7615_init_dfs_state(struct mt7615_phy *phy)
272 {
273 struct mt76_phy *mphy = phy->mt76;
274 struct ieee80211_hw *hw = mphy->hw;
275 struct cfg80211_chan_def *chandef = &hw->conf.chandef;
276
277 if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
278 return;
279
280 if (!(chandef->chan->flags & IEEE80211_CHAN_RADAR))
281 return;
282
283 if (mphy->chandef.chan->center_freq == chandef->chan->center_freq &&
284 mphy->chandef.width == chandef->width)
285 return;
286
287 phy->dfs_state = -1;
288 }
289
mt7615_set_channel(struct mt7615_phy * phy)290 int mt7615_set_channel(struct mt7615_phy *phy)
291 {
292 struct mt7615_dev *dev = phy->dev;
293 bool ext_phy = phy != &dev->phy;
294 int ret;
295
296 cancel_delayed_work_sync(&phy->mac_work);
297
298 mt7615_mutex_acquire(dev);
299
300 set_bit(MT76_RESET, &phy->mt76->state);
301
302 mt7615_init_dfs_state(phy);
303 mt76_set_channel(phy->mt76);
304
305 if (is_mt7615(&dev->mt76) && dev->flash_eeprom) {
306 mt7615_mcu_apply_rx_dcoc(phy);
307 mt7615_mcu_apply_tx_dpd(phy);
308 }
309
310 ret = mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD_CHANNEL_SWITCH);
311 if (ret)
312 goto out;
313
314 mt7615_mac_set_timing(phy);
315 ret = mt7615_dfs_init_radar_detector(phy);
316 mt7615_mac_cca_stats_reset(phy);
317 mt7615_mcu_set_sku_en(phy, !mt76_testmode_enabled(&dev->mt76));
318
319 mt7615_mac_reset_counters(dev);
320 phy->noise = 0;
321 phy->chfreq = mt76_rr(dev, MT_CHFREQ(ext_phy));
322
323 out:
324 clear_bit(MT76_RESET, &phy->mt76->state);
325
326 mt7615_mutex_release(dev);
327
328 mt76_txq_schedule_all(phy->mt76);
329
330 if (!mt76_testmode_enabled(&dev->mt76))
331 ieee80211_queue_delayed_work(phy->mt76->hw, &phy->mac_work,
332 MT7615_WATCHDOG_TIME);
333
334 return ret;
335 }
336
337 static int
mt7615_queue_key_update(struct mt7615_dev * dev,enum set_key_cmd cmd,struct mt7615_sta * msta,struct ieee80211_key_conf * key)338 mt7615_queue_key_update(struct mt7615_dev *dev, enum set_key_cmd cmd,
339 struct mt7615_sta *msta,
340 struct ieee80211_key_conf *key)
341 {
342 struct mt7615_wtbl_desc *wd;
343
344 wd = kzalloc(sizeof(*wd), GFP_KERNEL);
345 if (!wd)
346 return -ENOMEM;
347
348 wd->type = MT7615_WTBL_KEY_DESC;
349 wd->sta = msta;
350
351 wd->key.key = kmemdup(key->key, key->keylen, GFP_KERNEL);
352 if (!wd->key.key) {
353 kfree(wd);
354 return -ENOMEM;
355 }
356 wd->key.cipher = key->cipher;
357 wd->key.keyidx = key->keyidx;
358 wd->key.keylen = key->keylen;
359 wd->key.cmd = cmd;
360
361 spin_lock_bh(&dev->mt76.lock);
362 list_add_tail(&wd->node, &dev->wd_head);
363 spin_unlock_bh(&dev->mt76.lock);
364
365 queue_work(dev->mt76.wq, &dev->wtbl_work);
366
367 return 0;
368 }
369
mt7615_set_key(struct ieee80211_hw * hw,enum set_key_cmd cmd,struct ieee80211_vif * vif,struct ieee80211_sta * sta,struct ieee80211_key_conf * key)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
mt7615_config(struct ieee80211_hw * hw,u32 changed)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
mt7615_conf_tx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u16 queue,const struct ieee80211_tx_queue_params * params)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
mt7615_configure_filter(struct ieee80211_hw * hw,unsigned int changed_flags,unsigned int * total_flags,u64 multicast)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
mt7615_bss_info_changed(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * info,u32 changed)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
mt7615_channel_switch_beacon(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct cfg80211_chan_def * chandef)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
mt7615_mac_sta_add(struct mt76_dev * mdev,struct ieee80211_vif * vif,struct ieee80211_sta * sta)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
mt7615_mac_sta_remove(struct mt76_dev * mdev,struct ieee80211_vif * vif,struct ieee80211_sta * sta)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
mt7615_sta_rate_tbl_update(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)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
mt7615_wake_tx_queue(struct ieee80211_hw * hw,struct ieee80211_txq * txq)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 dev->pm.last_activity = jiffies;
707 mt76_worker_schedule(&dev->mt76.tx_worker);
708 }
709
mt7615_tx(struct ieee80211_hw * hw,struct ieee80211_tx_control * control,struct sk_buff * skb)710 static void mt7615_tx(struct ieee80211_hw *hw,
711 struct ieee80211_tx_control *control,
712 struct sk_buff *skb)
713 {
714 struct mt7615_dev *dev = mt7615_hw_dev(hw);
715 struct mt76_phy *mphy = hw->priv;
716 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
717 struct ieee80211_vif *vif = info->control.vif;
718 struct mt76_wcid *wcid = &dev->mt76.global_wcid;
719 struct mt7615_sta *msta = NULL;
720 int qid;
721
722 if (control->sta) {
723 msta = (struct mt7615_sta *)control->sta->drv_priv;
724 wcid = &msta->wcid;
725 }
726
727 if (vif && !control->sta) {
728 struct mt7615_vif *mvif;
729
730 mvif = (struct mt7615_vif *)vif->drv_priv;
731 msta = &mvif->sta;
732 wcid = &msta->wcid;
733 }
734
735 if (!test_bit(MT76_STATE_PM, &mphy->state)) {
736 dev->pm.last_activity = jiffies;
737 mt76_tx(mphy, control->sta, wcid, skb);
738 return;
739 }
740
741 qid = skb_get_queue_mapping(skb);
742 if (qid >= MT_TXQ_PSD) {
743 qid = IEEE80211_AC_BE;
744 skb_set_queue_mapping(skb, qid);
745 }
746
747 spin_lock_bh(&dev->pm.txq_lock);
748 if (!dev->pm.tx_q[qid].skb) {
749 ieee80211_stop_queues(hw);
750 dev->pm.tx_q[qid].msta = msta;
751 dev->pm.tx_q[qid].skb = skb;
752 queue_work(dev->mt76.wq, &dev->pm.wake_work);
753 } else {
754 dev_kfree_skb(skb);
755 }
756 spin_unlock_bh(&dev->pm.txq_lock);
757 }
758
mt7615_set_rts_threshold(struct ieee80211_hw * hw,u32 val)759 static int mt7615_set_rts_threshold(struct ieee80211_hw *hw, u32 val)
760 {
761 struct mt7615_dev *dev = mt7615_hw_dev(hw);
762 struct mt7615_phy *phy = mt7615_hw_phy(hw);
763
764 mt7615_mutex_acquire(dev);
765 mt7615_mcu_set_rts_thresh(phy, val);
766 mt7615_mutex_release(dev);
767
768 return 0;
769 }
770
771 static int
mt7615_ampdu_action(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_ampdu_params * params)772 mt7615_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
773 struct ieee80211_ampdu_params *params)
774 {
775 enum ieee80211_ampdu_mlme_action action = params->action;
776 struct mt7615_dev *dev = mt7615_hw_dev(hw);
777 struct ieee80211_sta *sta = params->sta;
778 struct ieee80211_txq *txq = sta->txq[params->tid];
779 struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv;
780 u16 tid = params->tid;
781 u16 ssn = params->ssn;
782 struct mt76_txq *mtxq;
783 int ret = 0;
784
785 if (!txq)
786 return -EINVAL;
787
788 mtxq = (struct mt76_txq *)txq->drv_priv;
789
790 mt7615_mutex_acquire(dev);
791
792 switch (action) {
793 case IEEE80211_AMPDU_RX_START:
794 mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, ssn,
795 params->buf_size);
796 mt7615_mcu_add_rx_ba(dev, params, true);
797 break;
798 case IEEE80211_AMPDU_RX_STOP:
799 mt76_rx_aggr_stop(&dev->mt76, &msta->wcid, tid);
800 mt7615_mcu_add_rx_ba(dev, params, false);
801 break;
802 case IEEE80211_AMPDU_TX_OPERATIONAL:
803 mtxq->aggr = true;
804 mtxq->send_bar = false;
805 mt7615_mcu_add_tx_ba(dev, params, true);
806 ssn = mt7615_mac_get_sta_tid_sn(dev, msta->wcid.idx, tid);
807 ieee80211_send_bar(vif, sta->addr, tid,
808 IEEE80211_SN_TO_SEQ(ssn));
809 break;
810 case IEEE80211_AMPDU_TX_STOP_FLUSH:
811 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
812 mtxq->aggr = false;
813 mt7615_mcu_add_tx_ba(dev, params, false);
814 break;
815 case IEEE80211_AMPDU_TX_START:
816 ssn = mt7615_mac_get_sta_tid_sn(dev, msta->wcid.idx, tid);
817 params->ssn = ssn;
818 ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;
819 break;
820 case IEEE80211_AMPDU_TX_STOP_CONT:
821 mtxq->aggr = false;
822 mt7615_mcu_add_tx_ba(dev, params, false);
823 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
824 break;
825 }
826 mt7615_mutex_release(dev);
827
828 return ret;
829 }
830
831 static int
mt7615_sta_add(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)832 mt7615_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
833 struct ieee80211_sta *sta)
834 {
835 return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NOTEXIST,
836 IEEE80211_STA_NONE);
837 }
838
839 static int
mt7615_sta_remove(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)840 mt7615_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
841 struct ieee80211_sta *sta)
842 {
843 return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NONE,
844 IEEE80211_STA_NOTEXIST);
845 }
846
847 static int
mt7615_get_stats(struct ieee80211_hw * hw,struct ieee80211_low_level_stats * stats)848 mt7615_get_stats(struct ieee80211_hw *hw,
849 struct ieee80211_low_level_stats *stats)
850 {
851 struct mt7615_phy *phy = mt7615_hw_phy(hw);
852 struct mib_stats *mib = &phy->mib;
853
854 mt7615_mutex_acquire(phy->dev);
855
856 stats->dot11RTSSuccessCount = mib->rts_cnt;
857 stats->dot11RTSFailureCount = mib->rts_retries_cnt;
858 stats->dot11FCSErrorCount = mib->fcs_err_cnt;
859 stats->dot11ACKFailureCount = mib->ack_fail_cnt;
860
861 memset(mib, 0, sizeof(*mib));
862
863 mt7615_mutex_release(phy->dev);
864
865 return 0;
866 }
867
868 static u64
mt7615_get_tsf(struct ieee80211_hw * hw,struct ieee80211_vif * vif)869 mt7615_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
870 {
871 struct mt7615_dev *dev = mt7615_hw_dev(hw);
872 union {
873 u64 t64;
874 u32 t32[2];
875 } tsf;
876
877 mt7615_mutex_acquire(dev);
878
879 mt76_set(dev, MT_LPON_T0CR, MT_LPON_T0CR_MODE); /* TSF read */
880 tsf.t32[0] = mt76_rr(dev, MT_LPON_UTTR0);
881 tsf.t32[1] = mt76_rr(dev, MT_LPON_UTTR1);
882
883 mt7615_mutex_release(dev);
884
885 return tsf.t64;
886 }
887
888 static void
mt7615_set_tsf(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u64 timestamp)889 mt7615_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
890 u64 timestamp)
891 {
892 struct mt7615_dev *dev = mt7615_hw_dev(hw);
893 union {
894 u64 t64;
895 u32 t32[2];
896 } tsf = { .t64 = timestamp, };
897
898 mt7615_mutex_acquire(dev);
899
900 mt76_wr(dev, MT_LPON_UTTR0, tsf.t32[0]);
901 mt76_wr(dev, MT_LPON_UTTR1, tsf.t32[1]);
902 /* TSF software overwrite */
903 mt76_set(dev, MT_LPON_T0CR, MT_LPON_T0CR_WRITE);
904
905 mt7615_mutex_release(dev);
906 }
907
908 static void
mt7615_set_coverage_class(struct ieee80211_hw * hw,s16 coverage_class)909 mt7615_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class)
910 {
911 struct mt7615_phy *phy = mt7615_hw_phy(hw);
912 struct mt7615_dev *dev = phy->dev;
913
914 mt7615_mutex_acquire(dev);
915 phy->coverage_class = max_t(s16, coverage_class, 0);
916 mt7615_mac_set_timing(phy);
917 mt7615_mutex_release(dev);
918 }
919
920 static int
mt7615_set_antenna(struct ieee80211_hw * hw,u32 tx_ant,u32 rx_ant)921 mt7615_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
922 {
923 struct mt7615_dev *dev = mt7615_hw_dev(hw);
924 struct mt7615_phy *phy = mt7615_hw_phy(hw);
925 int max_nss = hweight8(hw->wiphy->available_antennas_tx);
926 bool ext_phy = phy != &dev->phy;
927
928 if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss)
929 return -EINVAL;
930
931 if ((BIT(hweight8(tx_ant)) - 1) != tx_ant)
932 tx_ant = BIT(ffs(tx_ant) - 1) - 1;
933
934 mt7615_mutex_acquire(dev);
935
936 phy->mt76->antenna_mask = tx_ant;
937 if (ext_phy) {
938 if (dev->chainmask == 0xf)
939 tx_ant <<= 2;
940 else
941 tx_ant <<= 1;
942 }
943 phy->chainmask = tx_ant;
944
945 mt76_set_stream_caps(phy->mt76, true);
946
947 mt7615_mutex_release(dev);
948
949 return 0;
950 }
951
mt7615_roc_iter(void * priv,u8 * mac,struct ieee80211_vif * vif)952 static void mt7615_roc_iter(void *priv, u8 *mac,
953 struct ieee80211_vif *vif)
954 {
955 struct mt7615_phy *phy = priv;
956
957 mt7615_mcu_set_roc(phy, vif, NULL, 0);
958 }
959
mt7615_roc_work(struct work_struct * work)960 void mt7615_roc_work(struct work_struct *work)
961 {
962 struct mt7615_phy *phy;
963
964 phy = (struct mt7615_phy *)container_of(work, struct mt7615_phy,
965 roc_work);
966
967 if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
968 return;
969
970 mt7615_mutex_acquire(phy->dev);
971 ieee80211_iterate_active_interfaces(phy->mt76->hw,
972 IEEE80211_IFACE_ITER_RESUME_ALL,
973 mt7615_roc_iter, phy);
974 mt7615_mutex_release(phy->dev);
975 ieee80211_remain_on_channel_expired(phy->mt76->hw);
976 }
977
mt7615_roc_timer(struct timer_list * timer)978 void mt7615_roc_timer(struct timer_list *timer)
979 {
980 struct mt7615_phy *phy = from_timer(phy, timer, roc_timer);
981
982 ieee80211_queue_work(phy->mt76->hw, &phy->roc_work);
983 }
984
mt7615_scan_work(struct work_struct * work)985 void mt7615_scan_work(struct work_struct *work)
986 {
987 struct mt7615_phy *phy;
988
989 phy = (struct mt7615_phy *)container_of(work, struct mt7615_phy,
990 scan_work.work);
991
992 while (true) {
993 struct mt7615_mcu_rxd *rxd;
994 struct sk_buff *skb;
995
996 spin_lock_bh(&phy->dev->mt76.lock);
997 skb = __skb_dequeue(&phy->scan_event_list);
998 spin_unlock_bh(&phy->dev->mt76.lock);
999
1000 if (!skb)
1001 break;
1002
1003 rxd = (struct mt7615_mcu_rxd *)skb->data;
1004 if (rxd->eid == MCU_EVENT_SCHED_SCAN_DONE) {
1005 ieee80211_sched_scan_results(phy->mt76->hw);
1006 } else if (test_and_clear_bit(MT76_HW_SCANNING,
1007 &phy->mt76->state)) {
1008 struct cfg80211_scan_info info = {
1009 .aborted = false,
1010 };
1011
1012 ieee80211_scan_completed(phy->mt76->hw, &info);
1013 }
1014 dev_kfree_skb(skb);
1015 }
1016 }
1017
1018 static int
mt7615_hw_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_scan_request * req)1019 mt7615_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1020 struct ieee80211_scan_request *req)
1021 {
1022 struct mt7615_dev *dev = mt7615_hw_dev(hw);
1023 struct mt76_phy *mphy = hw->priv;
1024 int err;
1025
1026 mt7615_mutex_acquire(dev);
1027 err = mt7615_mcu_hw_scan(mphy->priv, vif, req);
1028 mt7615_mutex_release(dev);
1029
1030 return err;
1031 }
1032
1033 static void
mt7615_cancel_hw_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif)1034 mt7615_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1035 {
1036 struct mt7615_dev *dev = mt7615_hw_dev(hw);
1037 struct mt76_phy *mphy = hw->priv;
1038
1039 mt7615_mutex_acquire(dev);
1040 mt7615_mcu_cancel_hw_scan(mphy->priv, vif);
1041 mt7615_mutex_release(dev);
1042 }
1043
1044 static int
mt7615_start_sched_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct cfg80211_sched_scan_request * req,struct ieee80211_scan_ies * ies)1045 mt7615_start_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1046 struct cfg80211_sched_scan_request *req,
1047 struct ieee80211_scan_ies *ies)
1048 {
1049 struct mt7615_dev *dev = mt7615_hw_dev(hw);
1050 struct mt76_phy *mphy = hw->priv;
1051 int err;
1052
1053 mt7615_mutex_acquire(dev);
1054
1055 err = mt7615_mcu_sched_scan_req(mphy->priv, vif, req);
1056 if (err < 0)
1057 goto out;
1058
1059 err = mt7615_mcu_sched_scan_enable(mphy->priv, vif, true);
1060 out:
1061 mt7615_mutex_release(dev);
1062
1063 return err;
1064 }
1065
1066 static int
mt7615_stop_sched_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif)1067 mt7615_stop_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1068 {
1069 struct mt7615_dev *dev = mt7615_hw_dev(hw);
1070 struct mt76_phy *mphy = hw->priv;
1071 int err;
1072
1073 mt7615_mutex_acquire(dev);
1074 err = mt7615_mcu_sched_scan_enable(mphy->priv, vif, false);
1075 mt7615_mutex_release(dev);
1076
1077 return err;
1078 }
1079
mt7615_remain_on_channel(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_channel * chan,int duration,enum ieee80211_roc_type type)1080 static int mt7615_remain_on_channel(struct ieee80211_hw *hw,
1081 struct ieee80211_vif *vif,
1082 struct ieee80211_channel *chan,
1083 int duration,
1084 enum ieee80211_roc_type type)
1085 {
1086 struct mt7615_phy *phy = mt7615_hw_phy(hw);
1087 int err;
1088
1089 if (test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state))
1090 return 0;
1091
1092 mt7615_mutex_acquire(phy->dev);
1093
1094 err = mt7615_mcu_set_roc(phy, vif, chan, duration);
1095 if (err < 0) {
1096 clear_bit(MT76_STATE_ROC, &phy->mt76->state);
1097 goto out;
1098 }
1099
1100 if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, HZ)) {
1101 mt7615_mcu_set_roc(phy, vif, NULL, 0);
1102 clear_bit(MT76_STATE_ROC, &phy->mt76->state);
1103 err = -ETIMEDOUT;
1104 }
1105
1106 out:
1107 mt7615_mutex_release(phy->dev);
1108
1109 return err;
1110 }
1111
mt7615_cancel_remain_on_channel(struct ieee80211_hw * hw,struct ieee80211_vif * vif)1112 static int mt7615_cancel_remain_on_channel(struct ieee80211_hw *hw,
1113 struct ieee80211_vif *vif)
1114 {
1115 struct mt7615_phy *phy = mt7615_hw_phy(hw);
1116
1117 if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
1118 return 0;
1119
1120 del_timer_sync(&phy->roc_timer);
1121 cancel_work_sync(&phy->roc_work);
1122
1123 mt7615_mutex_acquire(phy->dev);
1124 mt7615_mcu_set_roc(phy, vif, NULL, 0);
1125 mt7615_mutex_release(phy->dev);
1126
1127 return 0;
1128 }
1129
1130 #ifdef CONFIG_PM
mt7615_suspend(struct ieee80211_hw * hw,struct cfg80211_wowlan * wowlan)1131 static int mt7615_suspend(struct ieee80211_hw *hw,
1132 struct cfg80211_wowlan *wowlan)
1133 {
1134 struct mt7615_dev *dev = mt7615_hw_dev(hw);
1135 struct mt7615_phy *phy = mt7615_hw_phy(hw);
1136 bool ext_phy = phy != &dev->phy;
1137 int err = 0;
1138
1139 cancel_delayed_work_sync(&dev->pm.ps_work);
1140 mt7615_free_pending_tx_skbs(dev, NULL);
1141
1142 mt7615_mutex_acquire(dev);
1143
1144 clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
1145 cancel_delayed_work_sync(&phy->scan_work);
1146 cancel_delayed_work_sync(&phy->mac_work);
1147
1148 mt76_set(dev, MT_WF_RFCR(ext_phy), MT_WF_RFCR_DROP_OTHER_BEACON);
1149
1150 set_bit(MT76_STATE_SUSPEND, &phy->mt76->state);
1151 ieee80211_iterate_active_interfaces(hw,
1152 IEEE80211_IFACE_ITER_RESUME_ALL,
1153 mt7615_mcu_set_suspend_iter, phy);
1154
1155 if (!mt7615_dev_running(dev))
1156 err = mt7615_mcu_set_hif_suspend(dev, true);
1157
1158 mt7615_mutex_release(dev);
1159
1160 return err;
1161 }
1162
mt7615_resume(struct ieee80211_hw * hw)1163 static int mt7615_resume(struct ieee80211_hw *hw)
1164 {
1165 struct mt7615_dev *dev = mt7615_hw_dev(hw);
1166 struct mt7615_phy *phy = mt7615_hw_phy(hw);
1167 bool running, ext_phy = phy != &dev->phy;
1168
1169 mt7615_mutex_acquire(dev);
1170
1171 running = mt7615_dev_running(dev);
1172 set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
1173
1174 if (!running) {
1175 int err;
1176
1177 err = mt7615_mcu_set_hif_suspend(dev, false);
1178 if (err < 0) {
1179 mt7615_mutex_release(dev);
1180 return err;
1181 }
1182 }
1183
1184 clear_bit(MT76_STATE_SUSPEND, &phy->mt76->state);
1185 ieee80211_iterate_active_interfaces(hw,
1186 IEEE80211_IFACE_ITER_RESUME_ALL,
1187 mt7615_mcu_set_suspend_iter, phy);
1188
1189 ieee80211_queue_delayed_work(hw, &phy->mac_work,
1190 MT7615_WATCHDOG_TIME);
1191 mt76_clear(dev, MT_WF_RFCR(ext_phy), MT_WF_RFCR_DROP_OTHER_BEACON);
1192
1193 mt7615_mutex_release(dev);
1194
1195 return 0;
1196 }
1197
mt7615_set_wakeup(struct ieee80211_hw * hw,bool enabled)1198 static void mt7615_set_wakeup(struct ieee80211_hw *hw, bool enabled)
1199 {
1200 struct mt7615_dev *dev = mt7615_hw_dev(hw);
1201 struct mt76_dev *mdev = &dev->mt76;
1202
1203 device_set_wakeup_enable(mdev->dev, enabled);
1204 }
1205
mt7615_set_rekey_data(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct cfg80211_gtk_rekey_data * data)1206 static void mt7615_set_rekey_data(struct ieee80211_hw *hw,
1207 struct ieee80211_vif *vif,
1208 struct cfg80211_gtk_rekey_data *data)
1209 {
1210 struct mt7615_dev *dev = mt7615_hw_dev(hw);
1211
1212 mt7615_mutex_acquire(dev);
1213 mt7615_mcu_update_gtk_rekey(hw, vif, data);
1214 mt7615_mutex_release(dev);
1215 }
1216 #endif /* CONFIG_PM */
1217
1218 const struct ieee80211_ops mt7615_ops = {
1219 .tx = mt7615_tx,
1220 .start = mt7615_start,
1221 .stop = mt7615_stop,
1222 .add_interface = mt7615_add_interface,
1223 .remove_interface = mt7615_remove_interface,
1224 .config = mt7615_config,
1225 .conf_tx = mt7615_conf_tx,
1226 .configure_filter = mt7615_configure_filter,
1227 .bss_info_changed = mt7615_bss_info_changed,
1228 .sta_add = mt7615_sta_add,
1229 .sta_remove = mt7615_sta_remove,
1230 .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
1231 .set_key = mt7615_set_key,
1232 .ampdu_action = mt7615_ampdu_action,
1233 .set_rts_threshold = mt7615_set_rts_threshold,
1234 .wake_tx_queue = mt7615_wake_tx_queue,
1235 .sta_rate_tbl_update = mt7615_sta_rate_tbl_update,
1236 .sw_scan_start = mt76_sw_scan,
1237 .sw_scan_complete = mt76_sw_scan_complete,
1238 .release_buffered_frames = mt76_release_buffered_frames,
1239 .get_txpower = mt76_get_txpower,
1240 .channel_switch_beacon = mt7615_channel_switch_beacon,
1241 .get_stats = mt7615_get_stats,
1242 .get_tsf = mt7615_get_tsf,
1243 .set_tsf = mt7615_set_tsf,
1244 .get_survey = mt76_get_survey,
1245 .get_antenna = mt76_get_antenna,
1246 .set_antenna = mt7615_set_antenna,
1247 .set_coverage_class = mt7615_set_coverage_class,
1248 .hw_scan = mt7615_hw_scan,
1249 .cancel_hw_scan = mt7615_cancel_hw_scan,
1250 .sched_scan_start = mt7615_start_sched_scan,
1251 .sched_scan_stop = mt7615_stop_sched_scan,
1252 .remain_on_channel = mt7615_remain_on_channel,
1253 .cancel_remain_on_channel = mt7615_cancel_remain_on_channel,
1254 CFG80211_TESTMODE_CMD(mt76_testmode_cmd)
1255 CFG80211_TESTMODE_DUMP(mt76_testmode_dump)
1256 #ifdef CONFIG_PM
1257 .suspend = mt7615_suspend,
1258 .resume = mt7615_resume,
1259 .set_wakeup = mt7615_set_wakeup,
1260 .set_rekey_data = mt7615_set_rekey_data,
1261 #endif /* CONFIG_PM */
1262 };
1263 EXPORT_SYMBOL_GPL(mt7615_ops);
1264
1265 MODULE_LICENSE("Dual BSD/GPL");
1266