blob: 945d9b2a4228394d5eb157c773a10ac1906ec1da [file] [log] [blame]
developer0f312e82022-11-01 12:31:52 +08001// SPDX-License-Identifier: ISC
2/*
3 * Copyright (C) 2022 MediaTek Inc.
4 */
5
6#include "mt7996.h"
7#include "mcu.h"
8
9static bool mt7996_dev_running(struct mt7996_dev *dev)
10{
11 struct mt7996_phy *phy;
12
13 if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state))
14 return true;
15
16 phy = mt7996_phy2(dev);
17 if (phy && test_bit(MT76_STATE_RUNNING, &phy->mt76->state))
18 return true;
19
20 phy = mt7996_phy3(dev);
21
22 return phy && test_bit(MT76_STATE_RUNNING, &phy->mt76->state);
23}
24
25static int mt7996_start(struct ieee80211_hw *hw)
26{
27 struct mt7996_dev *dev = mt7996_hw_dev(hw);
28 struct mt7996_phy *phy = mt7996_hw_phy(hw);
29 bool running;
30 int ret;
31
32 flush_work(&dev->init_work);
33
34 mutex_lock(&dev->mt76.mutex);
35
36 running = mt7996_dev_running(dev);
37 if (!running) {
38 ret = mt7996_mcu_set_hdr_trans(dev, true);
39 if (ret)
40 goto out;
41 }
42
43 mt7996_mac_enable_nf(dev, phy->mt76->band_idx);
44
45 ret = mt7996_mcu_set_rts_thresh(phy, 0x92b);
46 if (ret)
47 goto out;
48
49 ret = mt7996_mcu_set_chan_info(phy, UNI_CHANNEL_RX_PATH);
50 if (ret)
51 goto out;
52
53 set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
54
55 ieee80211_iterate_interfaces(dev->mt76.hw,
56 IEEE80211_IFACE_ITER_RESUME_ALL,
57 mt7996_mcu_set_pm, dev->mt76.hw);
58
59 ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
60 MT7996_WATCHDOG_TIME);
61
62 if (!running)
63 mt7996_mac_reset_counters(phy);
64
65out:
66 mutex_unlock(&dev->mt76.mutex);
67
68 return ret;
69}
70
71static void mt7996_stop(struct ieee80211_hw *hw)
72{
73 struct mt7996_dev *dev = mt7996_hw_dev(hw);
74 struct mt7996_phy *phy = mt7996_hw_phy(hw);
75
76 cancel_delayed_work_sync(&phy->mt76->mac_work);
77
78 mutex_lock(&dev->mt76.mutex);
79
80 clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
81
82 ieee80211_iterate_interfaces(dev->mt76.hw,
83 IEEE80211_IFACE_ITER_RESUME_ALL,
84 mt7996_mcu_set_pm, dev->mt76.hw);
85
86 mutex_unlock(&dev->mt76.mutex);
87}
88
89static inline int get_free_idx(u32 mask, u8 start, u8 end)
90{
91 return ffs(~mask & GENMASK(end, start));
92}
93
94static int get_omac_idx(enum nl80211_iftype type, u64 mask)
95{
96 int i;
97
98 switch (type) {
99 case NL80211_IFTYPE_MESH_POINT:
100 case NL80211_IFTYPE_ADHOC:
101 case NL80211_IFTYPE_STATION:
102 /* prefer hw bssid slot 1-3 */
103 i = get_free_idx(mask, HW_BSSID_1, HW_BSSID_3);
104 if (i)
105 return i - 1;
106
107 if (type != NL80211_IFTYPE_STATION)
108 break;
109
110 i = get_free_idx(mask, EXT_BSSID_1, EXT_BSSID_MAX);
111 if (i)
112 return i - 1;
113
114 if (~mask & BIT(HW_BSSID_0))
115 return HW_BSSID_0;
116
117 break;
118 case NL80211_IFTYPE_MONITOR:
119 case NL80211_IFTYPE_AP:
120 /* ap uses hw bssid 0 and ext bssid */
121 if (~mask & BIT(HW_BSSID_0))
122 return HW_BSSID_0;
123
124 i = get_free_idx(mask, EXT_BSSID_1, EXT_BSSID_MAX);
125 if (i)
126 return i - 1;
127
128 break;
129 default:
130 WARN_ON(1);
131 break;
132 }
133
134 return -1;
135}
136
137static void mt7996_init_bitrate_mask(struct ieee80211_vif *vif)
138{
139 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
140 int i;
141
142 for (i = 0; i < ARRAY_SIZE(mvif->bitrate_mask.control); i++) {
143 mvif->bitrate_mask.control[i].gi = NL80211_TXRATE_DEFAULT_GI;
144 mvif->bitrate_mask.control[i].he_gi = 0xff;
145 mvif->bitrate_mask.control[i].he_ltf = 0xff;
146 mvif->bitrate_mask.control[i].legacy = GENMASK(31, 0);
147 memset(mvif->bitrate_mask.control[i].ht_mcs, 0xff,
148 sizeof(mvif->bitrate_mask.control[i].ht_mcs));
149 memset(mvif->bitrate_mask.control[i].vht_mcs, 0xff,
150 sizeof(mvif->bitrate_mask.control[i].vht_mcs));
151 memset(mvif->bitrate_mask.control[i].he_mcs, 0xff,
152 sizeof(mvif->bitrate_mask.control[i].he_mcs));
153 }
154}
155
156static int mt7996_add_interface(struct ieee80211_hw *hw,
157 struct ieee80211_vif *vif)
158{
159 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
160 struct mt7996_dev *dev = mt7996_hw_dev(hw);
161 struct mt7996_phy *phy = mt7996_hw_phy(hw);
162 struct mt76_txq *mtxq;
163 u8 band_idx = phy->mt76->band_idx;
164 int idx, ret = 0;
165
166 mutex_lock(&dev->mt76.mutex);
167
168 if (vif->type == NL80211_IFTYPE_MONITOR &&
169 is_zero_ether_addr(vif->addr))
170 phy->monitor_vif = vif;
171
172 mvif->mt76.idx = __ffs64(~dev->mt76.vif_mask);
173 if (mvif->mt76.idx >= (MT7996_MAX_INTERFACES << dev->dbdc_support)) {
174 ret = -ENOSPC;
175 goto out;
176 }
177
178 idx = get_omac_idx(vif->type, phy->omac_mask);
179 if (idx < 0) {
180 ret = -ENOSPC;
181 goto out;
182 }
183 mvif->mt76.omac_idx = idx;
184 mvif->phy = phy;
185 mvif->mt76.band_idx = band_idx;
186 mvif->mt76.wmm_idx = band_idx;
187
188 ret = mt7996_mcu_add_dev_info(phy, vif, true);
189 if (ret)
190 goto out;
191
192 ret = mt7996_mcu_set_radio_en(phy, true);
193 if (ret)
194 goto out;
195
196 dev->mt76.vif_mask |= BIT_ULL(mvif->mt76.idx);
197 phy->omac_mask |= BIT_ULL(mvif->mt76.omac_idx);
198
199 idx = MT7996_WTBL_RESERVED - mvif->mt76.idx;
200
201 INIT_LIST_HEAD(&mvif->sta.rc_list);
202 INIT_LIST_HEAD(&mvif->sta.poll_list);
203 mvif->sta.wcid.idx = idx;
204 mvif->sta.wcid.phy_idx = band_idx;
205 mvif->sta.wcid.hw_key_idx = -1;
206 mvif->sta.wcid.tx_info |= MT_WCID_TX_INFO_SET;
207 mt76_packet_id_init(&mvif->sta.wcid);
208
209 mt7996_mac_wtbl_update(dev, idx,
210 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
211
212 if (vif->txq) {
213 mtxq = (struct mt76_txq *)vif->txq->drv_priv;
214 mtxq->wcid = idx;
215 }
216
217 if (vif->type != NL80211_IFTYPE_AP &&
218 (!mvif->mt76.omac_idx || mvif->mt76.omac_idx > 3))
219 vif->offload_flags = 0;
220 vif->offload_flags |= IEEE80211_OFFLOAD_ENCAP_4ADDR;
221
222 mt7996_init_bitrate_mask(vif);
223 memset(&mvif->cap, -1, sizeof(mvif->cap));
224
225 mt7996_mcu_add_bss_info(phy, vif, true);
226 mt7996_mcu_add_sta(dev, vif, NULL, true);
227 rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid);
228
229out:
230 mutex_unlock(&dev->mt76.mutex);
231
232 return ret;
233}
234
235static void mt7996_remove_interface(struct ieee80211_hw *hw,
236 struct ieee80211_vif *vif)
237{
238 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
239 struct mt7996_sta *msta = &mvif->sta;
240 struct mt7996_dev *dev = mt7996_hw_dev(hw);
241 struct mt7996_phy *phy = mt7996_hw_phy(hw);
242 int idx = msta->wcid.idx;
243
244 mt7996_mcu_add_bss_info(phy, vif, false);
245 mt7996_mcu_add_sta(dev, vif, NULL, false);
246
247 if (vif == phy->monitor_vif)
248 phy->monitor_vif = NULL;
249
250 mt7996_mcu_add_dev_info(phy, vif, false);
251 mt7996_mcu_set_radio_en(phy, false);
252
253 rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
254
255 mutex_lock(&dev->mt76.mutex);
256 dev->mt76.vif_mask &= ~BIT_ULL(mvif->mt76.idx);
257 phy->omac_mask &= ~BIT_ULL(mvif->mt76.omac_idx);
258 mutex_unlock(&dev->mt76.mutex);
259
260 spin_lock_bh(&dev->sta_poll_lock);
261 if (!list_empty(&msta->poll_list))
262 list_del_init(&msta->poll_list);
263 spin_unlock_bh(&dev->sta_poll_lock);
264
265 mt76_packet_id_flush(&dev->mt76, &msta->wcid);
266}
267
268int mt7996_set_channel(struct mt7996_phy *phy)
269{
270 struct mt7996_dev *dev = phy->dev;
271 int ret;
272
273 cancel_delayed_work_sync(&phy->mt76->mac_work);
274
275 mutex_lock(&dev->mt76.mutex);
276 set_bit(MT76_RESET, &phy->mt76->state);
277
278 mt76_set_channel(phy->mt76);
279
280 ret = mt7996_mcu_set_chan_info(phy, UNI_CHANNEL_SWITCH);
281 if (ret)
282 goto out;
283
284 mt7996_mac_set_timing(phy);
285 ret = mt7996_dfs_init_radar_detector(phy);
286 mt7996_mac_cca_stats_reset(phy);
287
288 mt7996_mac_reset_counters(phy);
289 phy->noise = 0;
290
291out:
292 clear_bit(MT76_RESET, &phy->mt76->state);
293 mutex_unlock(&dev->mt76.mutex);
294
295 mt76_txq_schedule_all(phy->mt76);
296
297 ieee80211_queue_delayed_work(phy->mt76->hw,
298 &phy->mt76->mac_work,
299 MT7996_WATCHDOG_TIME);
300
301 return ret;
302}
303
304static int mt7996_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
305 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
306 struct ieee80211_key_conf *key)
307{
308 struct mt7996_dev *dev = mt7996_hw_dev(hw);
309 struct mt7996_phy *phy = mt7996_hw_phy(hw);
310 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
311 struct mt7996_sta *msta = sta ? (struct mt7996_sta *)sta->drv_priv :
312 &mvif->sta;
313 struct mt76_wcid *wcid = &msta->wcid;
314 u8 *wcid_keyidx = &wcid->hw_key_idx;
315 int idx = key->keyidx;
316 int err = 0;
317
318 /* The hardware does not support per-STA RX GTK, fallback
319 * to software mode for these.
320 */
321 if ((vif->type == NL80211_IFTYPE_ADHOC ||
322 vif->type == NL80211_IFTYPE_MESH_POINT) &&
323 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
324 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
325 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
326 return -EOPNOTSUPP;
327
328 /* fall back to sw encryption for unsupported ciphers */
329 switch (key->cipher) {
330 case WLAN_CIPHER_SUITE_AES_CMAC:
331 wcid_keyidx = &wcid->hw_key_idx2;
332 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
333 break;
334 case WLAN_CIPHER_SUITE_TKIP:
335 case WLAN_CIPHER_SUITE_CCMP:
336 case WLAN_CIPHER_SUITE_CCMP_256:
337 case WLAN_CIPHER_SUITE_GCMP:
338 case WLAN_CIPHER_SUITE_GCMP_256:
339 case WLAN_CIPHER_SUITE_SMS4:
340 break;
341 case WLAN_CIPHER_SUITE_WEP40:
342 case WLAN_CIPHER_SUITE_WEP104:
343 default:
344 return -EOPNOTSUPP;
345 }
346
347 mutex_lock(&dev->mt76.mutex);
348
349 if (cmd == SET_KEY && !sta && !mvif->mt76.cipher) {
350 mvif->mt76.cipher = mt76_connac_mcu_get_cipher(key->cipher);
351 mt7996_mcu_add_bss_info(phy, vif, true);
352 }
353
354 if (cmd == SET_KEY)
355 *wcid_keyidx = idx;
356 else if (idx == *wcid_keyidx)
357 *wcid_keyidx = -1;
358 else
359 goto out;
360
361 mt76_wcid_key_setup(&dev->mt76, wcid,
362 cmd == SET_KEY ? key : NULL);
363
364 err = mt7996_mcu_add_key(&dev->mt76, vif, &msta->bip,
365 key, MCU_WMWA_UNI_CMD(STA_REC_UPDATE),
366 &msta->wcid, cmd);
367out:
368 mutex_unlock(&dev->mt76.mutex);
369
370 return err;
371}
372
373static int mt7996_config(struct ieee80211_hw *hw, u32 changed)
374{
375 struct mt7996_dev *dev = mt7996_hw_dev(hw);
376 struct mt7996_phy *phy = mt7996_hw_phy(hw);
377 int ret;
378
379 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
380 ieee80211_stop_queues(hw);
381 ret = mt7996_set_channel(phy);
382 if (ret)
383 return ret;
384 ieee80211_wake_queues(hw);
385 }
386
387 mutex_lock(&dev->mt76.mutex);
388
389 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
390 bool enabled = !!(hw->conf.flags & IEEE80211_CONF_MONITOR);
391
392 if (!enabled)
393 phy->rxfilter |= MT_WF_RFCR_DROP_OTHER_UC;
394 else
395 phy->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_UC;
396
397 mt76_rmw_field(dev, MT_DMA_DCR0(phy->mt76->band_idx),
398 MT_DMA_DCR0_RXD_G5_EN, enabled);
399 mt76_wr(dev, MT_WF_RFCR(phy->mt76->band_idx), phy->rxfilter);
400 }
401
402 mutex_unlock(&dev->mt76.mutex);
403
404 return 0;
405}
406
407static int
408mt7996_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
409 const struct ieee80211_tx_queue_params *params)
410{
411 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
412
413 /* no need to update right away, we'll get BSS_CHANGED_QOS */
414 queue = mt76_connac_lmac_mapping(queue);
415 mvif->queue_params[queue] = *params;
416
417 return 0;
418}
419
420static void mt7996_configure_filter(struct ieee80211_hw *hw,
421 unsigned int changed_flags,
422 unsigned int *total_flags,
423 u64 multicast)
424{
425 struct mt7996_dev *dev = mt7996_hw_dev(hw);
426 struct mt7996_phy *phy = mt7996_hw_phy(hw);
427 u32 ctl_flags = MT_WF_RFCR1_DROP_ACK |
428 MT_WF_RFCR1_DROP_BF_POLL |
429 MT_WF_RFCR1_DROP_BA |
430 MT_WF_RFCR1_DROP_CFEND |
431 MT_WF_RFCR1_DROP_CFACK;
432 u32 flags = 0;
433
434#define MT76_FILTER(_flag, _hw) do { \
435 flags |= *total_flags & FIF_##_flag; \
436 phy->rxfilter &= ~(_hw); \
437 phy->rxfilter |= !(flags & FIF_##_flag) * (_hw); \
438 } while (0)
439
440 mutex_lock(&dev->mt76.mutex);
441
442 phy->rxfilter &= ~(MT_WF_RFCR_DROP_OTHER_BSS |
443 MT_WF_RFCR_DROP_OTHER_BEACON |
444 MT_WF_RFCR_DROP_FRAME_REPORT |
445 MT_WF_RFCR_DROP_PROBEREQ |
446 MT_WF_RFCR_DROP_MCAST_FILTERED |
447 MT_WF_RFCR_DROP_MCAST |
448 MT_WF_RFCR_DROP_BCAST |
449 MT_WF_RFCR_DROP_DUPLICATE |
450 MT_WF_RFCR_DROP_A2_BSSID |
451 MT_WF_RFCR_DROP_UNWANTED_CTL |
452 MT_WF_RFCR_DROP_STBC_MULTI);
453
454 MT76_FILTER(OTHER_BSS, MT_WF_RFCR_DROP_OTHER_TIM |
455 MT_WF_RFCR_DROP_A3_MAC |
456 MT_WF_RFCR_DROP_A3_BSSID);
457
458 MT76_FILTER(FCSFAIL, MT_WF_RFCR_DROP_FCSFAIL);
459
460 MT76_FILTER(CONTROL, MT_WF_RFCR_DROP_CTS |
461 MT_WF_RFCR_DROP_RTS |
462 MT_WF_RFCR_DROP_CTL_RSV |
463 MT_WF_RFCR_DROP_NDPA);
464
465 *total_flags = flags;
466 mt76_wr(dev, MT_WF_RFCR(phy->mt76->band_idx), phy->rxfilter);
467
468 if (*total_flags & FIF_CONTROL)
469 mt76_clear(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags);
470 else
471 mt76_set(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags);
472
473 mutex_unlock(&dev->mt76.mutex);
474}
475
476static void
477mt7996_update_bss_color(struct ieee80211_hw *hw,
478 struct ieee80211_vif *vif,
479 struct cfg80211_he_bss_color *bss_color)
480{
481 struct mt7996_dev *dev = mt7996_hw_dev(hw);
482
483 switch (vif->type) {
484 case NL80211_IFTYPE_AP: {
485 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
486
487 if (mvif->mt76.omac_idx > HW_BSSID_MAX)
488 return;
489 fallthrough;
490 }
491 case NL80211_IFTYPE_STATION:
492 mt7996_mcu_update_bss_color(dev, vif, bss_color);
493 break;
494 default:
495 break;
496 }
497}
498
499static void mt7996_bss_info_changed(struct ieee80211_hw *hw,
500 struct ieee80211_vif *vif,
501 struct ieee80211_bss_conf *info,
502 u32 changed)
503{
504 struct mt7996_phy *phy = mt7996_hw_phy(hw);
505 struct mt7996_dev *dev = mt7996_hw_dev(hw);
506
507 mutex_lock(&dev->mt76.mutex);
508
509 /*
510 * station mode uses BSSID to map the wlan entry to a peer,
511 * and then peer references bss_info_rfch to set bandwidth cap.
512 */
513 if (changed & BSS_CHANGED_BSSID &&
514 vif->type == NL80211_IFTYPE_STATION) {
515 bool join = !is_zero_ether_addr(info->bssid);
516
517 mt7996_mcu_add_bss_info(phy, vif, join);
518 mt7996_mcu_add_sta(dev, vif, NULL, join);
519 }
520
521 if (changed & BSS_CHANGED_ASSOC) {
522 mt7996_mcu_add_bss_info(phy, vif, info->assoc);
523 mt7996_mcu_add_obss_spr(dev, vif, info->he_obss_pd.enable);
524 }
525
526 if (changed & BSS_CHANGED_ERP_SLOT) {
527 int slottime = info->use_short_slot ? 9 : 20;
528
529 if (slottime != phy->slottime) {
530 phy->slottime = slottime;
531 mt7996_mac_set_timing(phy);
532 }
533 }
534
535 if (changed & BSS_CHANGED_BEACON_ENABLED && info->enable_beacon) {
536 mt7996_mcu_add_bss_info(phy, vif, true);
537 mt7996_mcu_add_sta(dev, vif, NULL, true);
538 }
539
540 /* ensure that enable txcmd_mode after bss_info */
541 if (changed & (BSS_CHANGED_QOS | BSS_CHANGED_BEACON_ENABLED))
542 mt7996_mcu_set_tx(dev, vif);
543
544 if (changed & BSS_CHANGED_HE_OBSS_PD)
545 mt7996_mcu_add_obss_spr(dev, vif, info->he_obss_pd.enable);
546
547 if (changed & BSS_CHANGED_HE_BSS_COLOR)
548 mt7996_update_bss_color(hw, vif, &info->he_bss_color);
549
550 if (changed & (BSS_CHANGED_BEACON |
551 BSS_CHANGED_BEACON_ENABLED))
552 mt7996_mcu_add_beacon(hw, vif, info->enable_beacon);
553
554 if (changed & BSS_CHANGED_UNSOL_BCAST_PROBE_RESP ||
555 changed & BSS_CHANGED_FILS_DISCOVERY)
556 mt7996_mcu_beacon_inband_discov(dev, vif, changed);
557
558 mutex_unlock(&dev->mt76.mutex);
559}
560
561static void
562mt7996_channel_switch_beacon(struct ieee80211_hw *hw,
563 struct ieee80211_vif *vif,
564 struct cfg80211_chan_def *chandef)
565{
566 struct mt7996_dev *dev = mt7996_hw_dev(hw);
567
568 mutex_lock(&dev->mt76.mutex);
569 mt7996_mcu_add_beacon(hw, vif, true);
570 mutex_unlock(&dev->mt76.mutex);
571}
572
573int mt7996_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
574 struct ieee80211_sta *sta)
575{
576 struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76);
577 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
578 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
579 u8 band_idx = mvif->phy->mt76->band_idx;
580 int ret, idx;
581
582 idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7996_WTBL_STA);
583 if (idx < 0)
584 return -ENOSPC;
585
586 INIT_LIST_HEAD(&msta->rc_list);
587 INIT_LIST_HEAD(&msta->poll_list);
588 msta->vif = mvif;
589 msta->wcid.sta = 1;
590 msta->wcid.idx = idx;
591 msta->wcid.phy_idx = band_idx;
592 msta->wcid.tx_info |= MT_WCID_TX_INFO_SET;
593 msta->jiffies = jiffies;
594
595 mt7996_mac_wtbl_update(dev, idx,
596 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
597
598 ret = mt7996_mcu_add_sta(dev, vif, sta, true);
599 if (ret)
600 return ret;
601
602 return mt7996_mcu_add_rate_ctrl(dev, vif, sta, false);
603}
604
605void mt7996_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
606 struct ieee80211_sta *sta)
607{
608 struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76);
609 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
610 int i;
611
612 mt7996_mcu_add_sta(dev, vif, sta, false);
613
614 mt7996_mac_wtbl_update(dev, msta->wcid.idx,
615 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
616
617 for (i = 0; i < ARRAY_SIZE(msta->twt.flow); i++)
618 mt7996_mac_twt_teardown_flow(dev, msta, i);
619
620 spin_lock_bh(&dev->sta_poll_lock);
621 if (!list_empty(&msta->poll_list))
622 list_del_init(&msta->poll_list);
623 if (!list_empty(&msta->rc_list))
624 list_del_init(&msta->rc_list);
625 spin_unlock_bh(&dev->sta_poll_lock);
626}
627
628static void mt7996_tx(struct ieee80211_hw *hw,
629 struct ieee80211_tx_control *control,
630 struct sk_buff *skb)
631{
632 struct mt7996_dev *dev = mt7996_hw_dev(hw);
633 struct mt76_phy *mphy = hw->priv;
634 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
635 struct ieee80211_vif *vif = info->control.vif;
636 struct mt76_wcid *wcid = &dev->mt76.global_wcid;
637
638 if (control->sta) {
639 struct mt7996_sta *sta;
640
641 sta = (struct mt7996_sta *)control->sta->drv_priv;
642 wcid = &sta->wcid;
643 }
644
645 if (vif && !control->sta) {
646 struct mt7996_vif *mvif;
647
648 mvif = (struct mt7996_vif *)vif->drv_priv;
649 wcid = &mvif->sta.wcid;
650 }
651
652 mt76_tx(mphy, control->sta, wcid, skb);
653}
654
655static int mt7996_set_rts_threshold(struct ieee80211_hw *hw, u32 val)
656{
657 struct mt7996_phy *phy = mt7996_hw_phy(hw);
658 int ret;
659
660 mutex_lock(&phy->dev->mt76.mutex);
661 ret = mt7996_mcu_set_rts_thresh(phy, val);
662 mutex_unlock(&phy->dev->mt76.mutex);
663
664 return ret;
665}
666
667static int
668mt7996_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
669 struct ieee80211_ampdu_params *params)
670{
671 enum ieee80211_ampdu_mlme_action action = params->action;
672 struct mt7996_dev *dev = mt7996_hw_dev(hw);
673 struct ieee80211_sta *sta = params->sta;
674 struct ieee80211_txq *txq = sta->txq[params->tid];
675 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
676 u16 tid = params->tid;
677 u16 ssn = params->ssn;
678 struct mt76_txq *mtxq;
679 int ret = 0;
680
681 if (!txq)
682 return -EINVAL;
683
684 mtxq = (struct mt76_txq *)txq->drv_priv;
685
686 mutex_lock(&dev->mt76.mutex);
687 switch (action) {
688 case IEEE80211_AMPDU_RX_START:
689 mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, ssn,
690 params->buf_size);
691 ret = mt7996_mcu_add_rx_ba(dev, params, true);
692 break;
693 case IEEE80211_AMPDU_RX_STOP:
694 mt76_rx_aggr_stop(&dev->mt76, &msta->wcid, tid);
695 ret = mt7996_mcu_add_rx_ba(dev, params, false);
696 break;
697 case IEEE80211_AMPDU_TX_OPERATIONAL:
698 mtxq->aggr = true;
699 mtxq->send_bar = false;
700 ret = mt7996_mcu_add_tx_ba(dev, params, true);
701 break;
702 case IEEE80211_AMPDU_TX_STOP_FLUSH:
703 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
704 mtxq->aggr = false;
705 clear_bit(tid, &msta->ampdu_state);
706 ret = mt7996_mcu_add_tx_ba(dev, params, false);
707 break;
708 case IEEE80211_AMPDU_TX_START:
709 set_bit(tid, &msta->ampdu_state);
710 ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;
711 break;
712 case IEEE80211_AMPDU_TX_STOP_CONT:
713 mtxq->aggr = false;
714 clear_bit(tid, &msta->ampdu_state);
715 ret = mt7996_mcu_add_tx_ba(dev, params, false);
716 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
717 break;
718 }
719 mutex_unlock(&dev->mt76.mutex);
720
721 return ret;
722}
723
724static int
725mt7996_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
726 struct ieee80211_sta *sta)
727{
728 return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NOTEXIST,
729 IEEE80211_STA_NONE);
730}
731
732static int
733mt7996_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
734 struct ieee80211_sta *sta)
735{
736 return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NONE,
737 IEEE80211_STA_NOTEXIST);
738}
739
740static int
741mt7996_get_stats(struct ieee80211_hw *hw,
742 struct ieee80211_low_level_stats *stats)
743{
744 struct mt7996_phy *phy = mt7996_hw_phy(hw);
745 struct mt7996_dev *dev = mt7996_hw_dev(hw);
746 struct mib_stats *mib = &phy->mib;
747
748 mutex_lock(&dev->mt76.mutex);
749
750 stats->dot11RTSSuccessCount = mib->rts_cnt;
751 stats->dot11RTSFailureCount = mib->rts_retries_cnt;
752 stats->dot11FCSErrorCount = mib->fcs_err_cnt;
753 stats->dot11ACKFailureCount = mib->ack_fail_cnt;
754
755 mutex_unlock(&dev->mt76.mutex);
756
757 return 0;
758}
759
760u64 __mt7996_get_tsf(struct ieee80211_hw *hw, struct mt7996_vif *mvif)
761{
762 struct mt7996_dev *dev = mt7996_hw_dev(hw);
763 struct mt7996_phy *phy = mt7996_hw_phy(hw);
764 union {
765 u64 t64;
766 u32 t32[2];
767 } tsf;
768 u16 n;
769
770 lockdep_assert_held(&dev->mt76.mutex);
771
772 n = mvif->mt76.omac_idx > HW_BSSID_MAX ? HW_BSSID_0
773 : mvif->mt76.omac_idx;
774 /* TSF software read */
775 mt76_rmw(dev, MT_LPON_TCR(phy->mt76->band_idx, n), MT_LPON_TCR_SW_MODE,
776 MT_LPON_TCR_SW_READ);
777 tsf.t32[0] = mt76_rr(dev, MT_LPON_UTTR0(phy->mt76->band_idx));
778 tsf.t32[1] = mt76_rr(dev, MT_LPON_UTTR1(phy->mt76->band_idx));
779
780 return tsf.t64;
781}
782
783static u64
784mt7996_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
785{
786 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
787 struct mt7996_dev *dev = mt7996_hw_dev(hw);
788 u64 ret;
789
790 mutex_lock(&dev->mt76.mutex);
791 ret = __mt7996_get_tsf(hw, mvif);
792 mutex_unlock(&dev->mt76.mutex);
793
794 return ret;
795}
796
797static void
798mt7996_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
799 u64 timestamp)
800{
801 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
802 struct mt7996_dev *dev = mt7996_hw_dev(hw);
803 struct mt7996_phy *phy = mt7996_hw_phy(hw);
804 union {
805 u64 t64;
806 u32 t32[2];
807 } tsf = { .t64 = timestamp, };
808 u16 n;
809
810 mutex_lock(&dev->mt76.mutex);
811
812 n = mvif->mt76.omac_idx > HW_BSSID_MAX ? HW_BSSID_0
813 : mvif->mt76.omac_idx;
814 mt76_wr(dev, MT_LPON_UTTR0(phy->mt76->band_idx), tsf.t32[0]);
815 mt76_wr(dev, MT_LPON_UTTR1(phy->mt76->band_idx), tsf.t32[1]);
816 /* TSF software overwrite */
817 mt76_rmw(dev, MT_LPON_TCR(phy->mt76->band_idx, n), MT_LPON_TCR_SW_MODE,
818 MT_LPON_TCR_SW_WRITE);
819
820 mutex_unlock(&dev->mt76.mutex);
821}
822
823static void
824mt7996_offset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
825 s64 timestamp)
826{
827 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
828 struct mt7996_dev *dev = mt7996_hw_dev(hw);
829 struct mt7996_phy *phy = mt7996_hw_phy(hw);
830 union {
831 u64 t64;
832 u32 t32[2];
833 } tsf = { .t64 = timestamp, };
834 u16 n;
835
836 mutex_lock(&dev->mt76.mutex);
837
838 n = mvif->mt76.omac_idx > HW_BSSID_MAX ? HW_BSSID_0
839 : mvif->mt76.omac_idx;
840 mt76_wr(dev, MT_LPON_UTTR0(phy->mt76->band_idx), tsf.t32[0]);
841 mt76_wr(dev, MT_LPON_UTTR1(phy->mt76->band_idx), tsf.t32[1]);
842 /* TSF software adjust*/
843 mt76_rmw(dev, MT_LPON_TCR(phy->mt76->band_idx, n), MT_LPON_TCR_SW_MODE,
844 MT_LPON_TCR_SW_ADJUST);
845
846 mutex_unlock(&dev->mt76.mutex);
847}
848
849static void
850mt7996_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class)
851{
852 struct mt7996_phy *phy = mt7996_hw_phy(hw);
853 struct mt7996_dev *dev = phy->dev;
854
855 mutex_lock(&dev->mt76.mutex);
856 phy->coverage_class = max_t(s16, coverage_class, 0);
857 mt7996_mac_set_timing(phy);
858 mutex_unlock(&dev->mt76.mutex);
859}
860
861static int
862mt7996_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
863{
864 struct mt7996_dev *dev = mt7996_hw_dev(hw);
865 struct mt7996_phy *phy = mt7996_hw_phy(hw);
866 int max_nss = hweight8(hw->wiphy->available_antennas_tx);
867 u8 band_idx = phy->mt76->band_idx, shift = dev->chainshift[band_idx];
868
869 if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss)
870 return -EINVAL;
871
872 if ((BIT(hweight8(tx_ant)) - 1) != tx_ant)
873 tx_ant = BIT(ffs(tx_ant) - 1) - 1;
874
875 mutex_lock(&dev->mt76.mutex);
876
877 phy->mt76->antenna_mask = tx_ant;
878
879 /* restore to the origin chainmask which might have auxiliary path */
880 if (hweight8(tx_ant) == max_nss)
881 phy->mt76->chainmask = (dev->chainmask >> shift) << shift;
882 else
883 phy->mt76->chainmask = tx_ant << shift;
884
885 mt76_set_stream_caps(phy->mt76, true);
886 mt7996_set_stream_vht_txbf_caps(phy);
887 mt7996_set_stream_he_caps(phy);
888
889 mutex_unlock(&dev->mt76.mutex);
890
891 return 0;
892}
893
894static void mt7996_sta_statistics(struct ieee80211_hw *hw,
895 struct ieee80211_vif *vif,
896 struct ieee80211_sta *sta,
897 struct station_info *sinfo)
898{
899 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
900 struct rate_info *txrate = &msta->wcid.rate;
901
902 if (!txrate->legacy && !txrate->flags)
903 return;
904
905 if (txrate->legacy) {
906 sinfo->txrate.legacy = txrate->legacy;
907 } else {
908 sinfo->txrate.mcs = txrate->mcs;
909 sinfo->txrate.nss = txrate->nss;
910 sinfo->txrate.bw = txrate->bw;
911 sinfo->txrate.he_gi = txrate->he_gi;
912 sinfo->txrate.he_dcm = txrate->he_dcm;
913 sinfo->txrate.he_ru_alloc = txrate->he_ru_alloc;
914 }
915 sinfo->txrate.flags = txrate->flags;
916 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
917}
918
919static void mt7996_sta_rc_work(void *data, struct ieee80211_sta *sta)
920{
921 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
922 struct mt7996_dev *dev = msta->vif->phy->dev;
923 u32 *changed = data;
924
925 spin_lock_bh(&dev->sta_poll_lock);
926 msta->changed |= *changed;
927 if (list_empty(&msta->rc_list))
928 list_add_tail(&msta->rc_list, &dev->sta_rc_list);
929 spin_unlock_bh(&dev->sta_poll_lock);
930}
931
932static void mt7996_sta_rc_update(struct ieee80211_hw *hw,
933 struct ieee80211_vif *vif,
934 struct ieee80211_sta *sta,
935 u32 changed)
936{
937 struct mt7996_phy *phy = mt7996_hw_phy(hw);
938 struct mt7996_dev *dev = phy->dev;
939
940 mt7996_sta_rc_work(&changed, sta);
941 ieee80211_queue_work(hw, &dev->rc_work);
942}
943
944static int
945mt7996_set_bitrate_mask(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
946 const struct cfg80211_bitrate_mask *mask)
947{
948 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
949 struct mt7996_phy *phy = mt7996_hw_phy(hw);
950 struct mt7996_dev *dev = phy->dev;
951 u32 changed = IEEE80211_RC_SUPP_RATES_CHANGED;
952
953 mvif->bitrate_mask = *mask;
954
955 /* if multiple rates across different preambles are given we can
956 * reconfigure this info with all peers using sta_rec command with
957 * the below exception cases.
958 * - single rate : if a rate is passed along with different preambles,
959 * we select the highest one as fixed rate. i.e VHT MCS for VHT peers.
960 * - multiple rates: if it's not in range format i.e 0-{7,8,9} for VHT
961 * then multiple MCS setting (MCS 4,5,6) is not supported.
962 */
963 ieee80211_iterate_stations_atomic(hw, mt7996_sta_rc_work, &changed);
964 ieee80211_queue_work(hw, &dev->rc_work);
965
966 return 0;
967}
968
969static void mt7996_sta_set_4addr(struct ieee80211_hw *hw,
970 struct ieee80211_vif *vif,
971 struct ieee80211_sta *sta,
972 bool enabled)
973{
974 struct mt7996_dev *dev = mt7996_hw_dev(hw);
975 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
976
977 if (enabled)
978 set_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags);
979 else
980 clear_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags);
981
982 mt7996_mcu_wtbl_update_hdr_trans(dev, vif, sta);
983}
984
985static void mt7996_sta_set_decap_offload(struct ieee80211_hw *hw,
986 struct ieee80211_vif *vif,
987 struct ieee80211_sta *sta,
988 bool enabled)
989{
990 struct mt7996_dev *dev = mt7996_hw_dev(hw);
991 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
992
993 if (enabled)
994 set_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags);
995 else
996 clear_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags);
997
998 mt7996_mcu_wtbl_update_hdr_trans(dev, vif, sta);
999}
1000
1001static const char mt7996_gstrings_stats[][ETH_GSTRING_LEN] = {
1002 "tx_ampdu_cnt",
1003 "tx_stop_q_empty_cnt",
1004 "tx_mpdu_attempts",
1005 "tx_mpdu_success",
1006 "tx_rwp_fail_cnt",
1007 "tx_rwp_need_cnt",
1008 "tx_pkt_ebf_cnt",
1009 "tx_pkt_ibf_cnt",
1010 "tx_ampdu_len:0-1",
1011 "tx_ampdu_len:2-10",
1012 "tx_ampdu_len:11-19",
1013 "tx_ampdu_len:20-28",
1014 "tx_ampdu_len:29-37",
1015 "tx_ampdu_len:38-46",
1016 "tx_ampdu_len:47-55",
1017 "tx_ampdu_len:56-79",
1018 "tx_ampdu_len:80-103",
1019 "tx_ampdu_len:104-127",
1020 "tx_ampdu_len:128-151",
1021 "tx_ampdu_len:152-175",
1022 "tx_ampdu_len:176-199",
1023 "tx_ampdu_len:200-223",
1024 "tx_ampdu_len:224-247",
1025 "ba_miss_count",
1026 "tx_beamformer_ppdu_iBF",
1027 "tx_beamformer_ppdu_eBF",
1028 "tx_beamformer_rx_feedback_all",
1029 "tx_beamformer_rx_feedback_he",
1030 "tx_beamformer_rx_feedback_vht",
1031 "tx_beamformer_rx_feedback_ht",
1032 "tx_beamformer_rx_feedback_bw", /* zero based idx: 20, 40, 80, 160 */
1033 "tx_beamformer_rx_feedback_nc",
1034 "tx_beamformer_rx_feedback_nr",
1035 "tx_beamformee_ok_feedback_pkts",
1036 "tx_beamformee_feedback_trig",
1037 "tx_mu_beamforming",
1038 "tx_mu_mpdu",
1039 "tx_mu_successful_mpdu",
1040 "tx_su_successful_mpdu",
1041 "tx_msdu_pack_1",
1042 "tx_msdu_pack_2",
1043 "tx_msdu_pack_3",
1044 "tx_msdu_pack_4",
1045 "tx_msdu_pack_5",
1046 "tx_msdu_pack_6",
1047 "tx_msdu_pack_7",
1048 "tx_msdu_pack_8",
1049
1050 /* rx counters */
1051 "rx_fifo_full_cnt",
1052 "rx_mpdu_cnt",
1053 "channel_idle_cnt",
1054 "rx_vector_mismatch_cnt",
1055 "rx_delimiter_fail_cnt",
1056 "rx_len_mismatch_cnt",
1057 "rx_ampdu_cnt",
1058 "rx_ampdu_bytes_cnt",
1059 "rx_ampdu_valid_subframe_cnt",
1060 "rx_ampdu_valid_subframe_b_cnt",
1061 "rx_pfdrop_cnt",
1062 "rx_vec_queue_overflow_drop_cnt",
1063 "rx_ba_cnt",
1064
1065 /* per vif counters */
1066 "v_tx_mode_cck",
1067 "v_tx_mode_ofdm",
1068 "v_tx_mode_ht",
1069 "v_tx_mode_ht_gf",
1070 "v_tx_mode_vht",
1071 "v_tx_mode_he_su",
1072 "v_tx_mode_he_ext_su",
1073 "v_tx_mode_he_tb",
1074 "v_tx_mode_he_mu",
1075 "v_tx_bw_20",
1076 "v_tx_bw_40",
1077 "v_tx_bw_80",
1078 "v_tx_bw_160",
1079 "v_tx_mcs_0",
1080 "v_tx_mcs_1",
1081 "v_tx_mcs_2",
1082 "v_tx_mcs_3",
1083 "v_tx_mcs_4",
1084 "v_tx_mcs_5",
1085 "v_tx_mcs_6",
1086 "v_tx_mcs_7",
1087 "v_tx_mcs_8",
1088 "v_tx_mcs_9",
1089 "v_tx_mcs_10",
1090 "v_tx_mcs_11",
1091};
1092
1093#define MT7996_SSTATS_LEN ARRAY_SIZE(mt7996_gstrings_stats)
1094
1095/* Ethtool related API */
1096static
1097void mt7996_get_et_strings(struct ieee80211_hw *hw,
1098 struct ieee80211_vif *vif,
1099 u32 sset, u8 *data)
1100{
1101 if (sset == ETH_SS_STATS)
1102 memcpy(data, *mt7996_gstrings_stats,
1103 sizeof(mt7996_gstrings_stats));
1104}
1105
1106static
1107int mt7996_get_et_sset_count(struct ieee80211_hw *hw,
1108 struct ieee80211_vif *vif, int sset)
1109{
1110 if (sset == ETH_SS_STATS)
1111 return MT7996_SSTATS_LEN;
1112
1113 return 0;
1114}
1115
1116static void mt7996_ethtool_worker(void *wi_data, struct ieee80211_sta *sta)
1117{
1118 struct mt76_ethtool_worker_info *wi = wi_data;
1119 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
1120
1121 if (msta->vif->mt76.idx != wi->idx)
1122 return;
1123
1124 mt76_ethtool_worker(wi, &msta->stats);
1125}
1126
1127static
1128void mt7996_get_et_stats(struct ieee80211_hw *hw,
1129 struct ieee80211_vif *vif,
1130 struct ethtool_stats *stats, u64 *data)
1131{
1132 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1133 struct mt7996_phy *phy = mt7996_hw_phy(hw);
1134 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
1135 struct mt76_ethtool_worker_info wi = {
1136 .data = data,
1137 .idx = mvif->mt76.idx,
1138 };
1139 struct mib_stats *mib = &phy->mib;
1140 /* See mt7996_ampdu_stat_read_phy, etc */
1141 int i, n, ei = 0;
1142
1143 mutex_lock(&dev->mt76.mutex);
1144
1145 mt7996_mac_update_stats(phy);
1146
1147 data[ei++] = mib->tx_ampdu_cnt;
1148 data[ei++] = mib->tx_stop_q_empty_cnt;
1149 data[ei++] = mib->tx_mpdu_attempts_cnt;
1150 data[ei++] = mib->tx_mpdu_success_cnt;
1151 data[ei++] = mib->tx_rwp_fail_cnt;
1152 data[ei++] = mib->tx_rwp_need_cnt;
1153 data[ei++] = mib->tx_bf_ebf_ppdu_cnt;
1154 data[ei++] = mib->tx_bf_ibf_ppdu_cnt;
1155
1156 /* Tx ampdu stat */
1157 n = ARRAY_SIZE(dev->mt76.aggr_stats) / __MT_MAX_BAND * phy->mt76->band_idx;
1158 for (i = 0; i < 15 /*ARRAY_SIZE(bound)*/; i++)
1159 data[ei++] = dev->mt76.aggr_stats[i + n];
1160
1161 data[ei++] = phy->mib.ba_miss_cnt;
1162
1163 /* Tx Beamformer monitor */
1164 data[ei++] = mib->tx_bf_ibf_ppdu_cnt;
1165 data[ei++] = mib->tx_bf_ebf_ppdu_cnt;
1166
1167 /* Tx Beamformer Rx feedback monitor */
1168 data[ei++] = mib->tx_bf_rx_fb_all_cnt;
1169 data[ei++] = mib->tx_bf_rx_fb_he_cnt;
1170 data[ei++] = mib->tx_bf_rx_fb_vht_cnt;
1171 data[ei++] = mib->tx_bf_rx_fb_ht_cnt;
1172
1173 data[ei++] = mib->tx_bf_rx_fb_bw;
1174 data[ei++] = mib->tx_bf_rx_fb_nc_cnt;
1175 data[ei++] = mib->tx_bf_rx_fb_nr_cnt;
1176
1177 /* Tx Beamformee Rx NDPA & Tx feedback report */
1178 data[ei++] = mib->tx_bf_fb_cpl_cnt;
1179 data[ei++] = mib->tx_bf_fb_trig_cnt;
1180
1181 /* Tx SU & MU counters */
1182 data[ei++] = mib->tx_mu_bf_cnt;
1183 data[ei++] = mib->tx_mu_mpdu_cnt;
1184 data[ei++] = mib->tx_mu_acked_mpdu_cnt;
1185 data[ei++] = mib->tx_su_acked_mpdu_cnt;
1186
1187 /* Tx amsdu info (pack-count histogram) */
1188 for (i = 0; i < ARRAY_SIZE(mib->tx_amsdu); i++)
1189 data[ei++] = mib->tx_amsdu[i];
1190
1191 /* rx counters */
1192 data[ei++] = mib->rx_fifo_full_cnt;
1193 data[ei++] = mib->rx_mpdu_cnt;
1194 data[ei++] = mib->channel_idle_cnt;
1195 data[ei++] = mib->rx_vector_mismatch_cnt;
1196 data[ei++] = mib->rx_delimiter_fail_cnt;
1197 data[ei++] = mib->rx_len_mismatch_cnt;
1198 data[ei++] = mib->rx_ampdu_cnt;
1199 data[ei++] = mib->rx_ampdu_bytes_cnt;
1200 data[ei++] = mib->rx_ampdu_valid_subframe_cnt;
1201 data[ei++] = mib->rx_ampdu_valid_subframe_bytes_cnt;
1202 data[ei++] = mib->rx_pfdrop_cnt;
1203 data[ei++] = mib->rx_vec_queue_overflow_drop_cnt;
1204 data[ei++] = mib->rx_ba_cnt;
1205
1206 /* Add values for all stations owned by this vif */
1207 wi.initial_stat_idx = ei;
1208 ieee80211_iterate_stations_atomic(hw, mt7996_ethtool_worker, &wi);
1209
1210 mutex_unlock(&dev->mt76.mutex);
1211
1212 if (wi.sta_count == 0)
1213 return;
1214
1215 ei += wi.worker_stat_count;
1216 if (ei != MT7996_SSTATS_LEN)
1217 dev_err(dev->mt76.dev, "ei: %d MT7996_SSTATS_LEN: %d",
1218 ei, (int)MT7996_SSTATS_LEN);
1219}
1220
1221static void
1222mt7996_twt_teardown_request(struct ieee80211_hw *hw,
1223 struct ieee80211_sta *sta,
1224 u8 flowid)
1225{
1226 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
1227 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1228
1229 mutex_lock(&dev->mt76.mutex);
1230 mt7996_mac_twt_teardown_flow(dev, msta, flowid);
1231 mutex_unlock(&dev->mt76.mutex);
1232}
1233
1234static int
1235mt7996_set_radar_background(struct ieee80211_hw *hw,
1236 struct cfg80211_chan_def *chandef)
1237{
1238 struct mt7996_phy *phy = mt7996_hw_phy(hw);
1239 struct mt7996_dev *dev = phy->dev;
1240 int ret = -EINVAL;
1241 bool running;
1242
1243 mutex_lock(&dev->mt76.mutex);
1244
1245 if (dev->mt76.region == NL80211_DFS_UNSET)
1246 goto out;
1247
1248 if (dev->rdd2_phy && dev->rdd2_phy != phy) {
1249 /* rdd2 is already locked */
1250 ret = -EBUSY;
1251 goto out;
1252 }
1253
1254 /* rdd2 already configured on a radar channel */
1255 running = dev->rdd2_phy &&
1256 cfg80211_chandef_valid(&dev->rdd2_chandef) &&
1257 !!(dev->rdd2_chandef.chan->flags & IEEE80211_CHAN_RADAR);
1258
1259 if (!chandef || running ||
1260 !(chandef->chan->flags & IEEE80211_CHAN_RADAR)) {
1261 ret = mt7996_mcu_rdd_background_enable(phy, NULL);
1262 if (ret)
1263 goto out;
1264
1265 if (!running)
1266 goto update_phy;
1267 }
1268
1269 ret = mt7996_mcu_rdd_background_enable(phy, chandef);
1270 if (ret)
1271 goto out;
1272
1273update_phy:
1274 dev->rdd2_phy = chandef ? phy : NULL;
1275 if (chandef)
1276 dev->rdd2_chandef = *chandef;
1277out:
1278 mutex_unlock(&dev->mt76.mutex);
1279
1280 return ret;
1281}
1282
1283const struct ieee80211_ops mt7996_ops = {
1284 .tx = mt7996_tx,
1285 .start = mt7996_start,
1286 .stop = mt7996_stop,
1287 .add_interface = mt7996_add_interface,
1288 .remove_interface = mt7996_remove_interface,
1289 .config = mt7996_config,
1290 .conf_tx = mt7996_conf_tx,
1291 .configure_filter = mt7996_configure_filter,
1292 .bss_info_changed = mt7996_bss_info_changed,
1293 .sta_add = mt7996_sta_add,
1294 .sta_remove = mt7996_sta_remove,
1295 .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
1296 .sta_rc_update = mt7996_sta_rc_update,
1297 .set_key = mt7996_set_key,
1298 .ampdu_action = mt7996_ampdu_action,
1299 .set_rts_threshold = mt7996_set_rts_threshold,
1300 .wake_tx_queue = mt76_wake_tx_queue,
1301 .sw_scan_start = mt76_sw_scan,
1302 .sw_scan_complete = mt76_sw_scan_complete,
1303 .release_buffered_frames = mt76_release_buffered_frames,
1304 .get_txpower = mt76_get_txpower,
1305 .channel_switch_beacon = mt7996_channel_switch_beacon,
1306 .get_stats = mt7996_get_stats,
1307 .get_et_sset_count = mt7996_get_et_sset_count,
1308 .get_et_stats = mt7996_get_et_stats,
1309 .get_et_strings = mt7996_get_et_strings,
1310 .get_tsf = mt7996_get_tsf,
1311 .set_tsf = mt7996_set_tsf,
1312 .offset_tsf = mt7996_offset_tsf,
1313 .get_survey = mt76_get_survey,
1314 .get_antenna = mt76_get_antenna,
1315 .set_antenna = mt7996_set_antenna,
1316 .set_bitrate_mask = mt7996_set_bitrate_mask,
1317 .set_coverage_class = mt7996_set_coverage_class,
1318 .sta_statistics = mt7996_sta_statistics,
1319 .sta_set_4addr = mt7996_sta_set_4addr,
1320 .sta_set_decap_offload = mt7996_sta_set_decap_offload,
1321 .add_twt_setup = mt7996_mac_add_twt_setup,
1322 .twt_teardown_request = mt7996_twt_teardown_request,
1323#ifdef CONFIG_MAC80211_DEBUGFS
1324 .sta_add_debugfs = mt7996_sta_add_debugfs,
1325#endif
1326 .set_radar_background = mt7996_set_radar_background,
1327};