Debian Codegraph @

drivers/net/wireless/mediatek/mt76/mt7996/main.c

raw
1 // SPDX-License-Identifier: BSD-3-Clause-Clear
2 /*
3 * Copyright (C) 2022 MediaTek Inc.
4 */
5
6 #include "mt7996.h"
7 #include "mcu.h"
8 #include "mac.h"
9
10 int mt7996_run(struct mt7996_phy *phy)
11 {
12 struct mt7996_dev *dev = phy->dev;
13 int ret;
14
15 mt7996_mac_enable_nf(dev, phy->mt76->band_idx);
16
17 ret = mt7996_mcu_set_rts_thresh(phy, 0x92b);
18 if (ret)
19 return ret;
20
21 ret = mt7996_mcu_set_radio_en(phy, true);
22 if (ret)
23 return ret;
24
25 ret = mt7996_mcu_set_chan_info(phy, UNI_CHANNEL_RX_PATH);
26 if (ret)
27 return ret;
28
29 ret = mt7996_mcu_set_thermal_throttling(phy, MT7996_THERMAL_THROTTLE_MAX);
30 if (ret)
31 return ret;
32
33 ret = mt7996_mcu_set_thermal_protect(phy, true);
34 if (ret)
35 return ret;
36
37 set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
38
39 ieee80211_queue_delayed_work(dev->mphy.hw, &phy->mt76->mac_work,
40 MT7996_WATCHDOG_TIME);
41
42 if (!phy->counter_reset) {
43 mt7996_mac_reset_counters(phy);
44 phy->counter_reset = true;
45 }
46
47 return 0;
48 }
49
50 static int mt7996_start(struct ieee80211_hw *hw)
51 {
52 struct mt7996_dev *dev = mt7996_hw_dev(hw);
53 int ret;
54
55 flush_work(&dev->init_work);
56
57 mutex_lock(&dev->mt76.mutex);
58 ret = mt7996_mcu_set_hdr_trans(dev, true);
59 if (!ret && is_mt7992(&dev->mt76)) {
60 u8 queue = mt76_connac_lmac_mapping(IEEE80211_AC_VI);
61
62 ret = mt7996_mcu_cp_support(dev, queue);
63 }
64 mutex_unlock(&dev->mt76.mutex);
65
66 return ret;
67 }
68
69 static void mt7996_stop_phy(struct mt7996_phy *phy)
70 {
71 struct mt7996_dev *dev;
72
73 if (!phy || !test_bit(MT76_STATE_RUNNING, &phy->mt76->state))
74 return;
75
76 dev = phy->dev;
77
78 cancel_delayed_work_sync(&phy->mt76->mac_work);
79
80 mutex_lock(&dev->mt76.mutex);
81
82 mt7996_mcu_rdd_resume_tx(phy);
83 mt7996_mcu_set_radio_en(phy, false);
84
85 clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
86
87 mutex_unlock(&dev->mt76.mutex);
88 }
89
90 static void mt7996_stop(struct ieee80211_hw *hw, bool suspend)
91 {
92 }
93
94 static inline int get_free_idx(u64 mask, u8 start, u8 end)
95 {
96 if (~mask & GENMASK_ULL(end, start))
97 return __ffs64(~mask & GENMASK_ULL(end, start)) + 1;
98 return 0;
99 }
100
101 static int get_omac_idx(enum nl80211_iftype type, u64 mask)
102 {
103 int i;
104
105 switch (type) {
106 case NL80211_IFTYPE_MESH_POINT:
107 case NL80211_IFTYPE_ADHOC:
108 case NL80211_IFTYPE_STATION:
109 /* prefer hw bssid slot 1-3 */
110 i = get_free_idx(mask, HW_BSSID_1, HW_BSSID_3);
111 if (i)
112 return i - 1;
113
114 if (type != NL80211_IFTYPE_STATION)
115 break;
116
117 i = get_free_idx(mask, EXT_BSSID_1, EXT_BSSID_MAX);
118 if (i)
119 return i - 1;
120
121 if (~mask & BIT(HW_BSSID_0))
122 return HW_BSSID_0;
123
124 break;
125 case NL80211_IFTYPE_MONITOR:
126 case NL80211_IFTYPE_AP:
127 /* ap uses hw bssid 0 and ext bssid */
128 if (~mask & BIT(HW_BSSID_0))
129 return HW_BSSID_0;
130
131 i = get_free_idx(mask, EXT_BSSID_1, EXT_BSSID_MAX);
132 if (i)
133 return i - 1;
134
135 break;
136 default:
137 WARN_ON(1);
138 break;
139 }
140
141 return -1;
142 }
143
144 static int get_own_mld_idx(u64 mask, bool group_mld)
145 {
146 u8 start = group_mld ? 0 : 16;
147 u8 end = group_mld ? 15 : 63;
148 int idx;
149
150 idx = get_free_idx(mask, start, end);
151 if (idx)
152 return idx - 1;
153
154 /* If the 16-63 range is not available, perform another lookup in the
155 * range 0-15
156 */
157 if (!group_mld) {
158 idx = get_free_idx(mask, 0, 15);
159 if (idx)
160 return idx - 1;
161 }
162
163 return -EINVAL;
164 }
165
166 static void
167 mt7996_init_bitrate_mask(struct ieee80211_vif *vif, struct mt7996_vif_link *mlink)
168 {
169 int i;
170
171 for (i = 0; i < ARRAY_SIZE(mlink->bitrate_mask.control); i++) {
172 mlink->bitrate_mask.control[i].gi = NL80211_TXRATE_DEFAULT_GI;
173 mlink->bitrate_mask.control[i].he_gi = 0xff;
174 mlink->bitrate_mask.control[i].he_ltf = 0xff;
175 mlink->bitrate_mask.control[i].legacy = GENMASK(31, 0);
176 memset(mlink->bitrate_mask.control[i].ht_mcs, 0xff,
177 sizeof(mlink->bitrate_mask.control[i].ht_mcs));
178 memset(mlink->bitrate_mask.control[i].vht_mcs, 0xff,
179 sizeof(mlink->bitrate_mask.control[i].vht_mcs));
180 memset(mlink->bitrate_mask.control[i].he_mcs, 0xff,
181 sizeof(mlink->bitrate_mask.control[i].he_mcs));
182 }
183 }
184
185 static int
186 mt7996_set_hw_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
187 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
188 unsigned int link_id, struct ieee80211_key_conf *key)
189 {
190 struct mt7996_dev *dev = mt7996_hw_dev(hw);
191 struct ieee80211_bss_conf *link_conf;
192 struct mt7996_sta_link *msta_link;
193 struct mt7996_vif_link *link;
194 int idx = key->keyidx;
195 u8 *wcid_keyidx;
196 bool is_bigtk;
197 int err;
198
199 link = mt7996_vif_link(dev, vif, link_id);
200 if (!link)
201 return 0;
202
203 if (!mt7996_vif_link_phy(link))
204 return 0;
205
206 if (sta) {
207 struct mt7996_sta *msta;
208
209 msta = (struct mt7996_sta *)sta->drv_priv;
210 msta_link = mt76_dereference(msta->link[link_id],
211 &dev->mt76);
212 if (!msta_link)
213 return 0;
214
215 if (!msta_link->wcid.sta)
216 return -EOPNOTSUPP;
217 } else {
218 msta_link = &link->msta_link;
219 }
220 wcid_keyidx = &msta_link->wcid.hw_key_idx;
221
222 is_bigtk = key->keyidx == 6 || key->keyidx == 7;
223 switch (key->cipher) {
224 case WLAN_CIPHER_SUITE_AES_CMAC:
225 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
226 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
227 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
228 if (is_bigtk) {
229 wcid_keyidx = &msta_link->wcid.hw_key_idx2;
230 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
231 }
232 break;
233 default:
234 break;
235 }
236
237 link_conf = link_conf_dereference_protected(vif, link_id);
238 if (!link_conf)
239 link_conf = &vif->bss_conf;
240
241 if (cmd == SET_KEY && !sta && !link->mt76.cipher) {
242 link->mt76.cipher =
243 mt76_connac_mcu_get_cipher(key->cipher);
244 mt7996_mcu_add_bss_info(link->phy, vif, link_conf,
245 &link->mt76, msta_link, true);
246 }
247
248 if (cmd == SET_KEY)
249 *wcid_keyidx = idx;
250 else if (idx == *wcid_keyidx)
251 *wcid_keyidx = -1;
252
253 /* only do remove key for BIGTK */
254 if (cmd != SET_KEY && !is_bigtk)
255 return 0;
256
257 mt76_wcid_key_setup(&dev->mt76, &msta_link->wcid, key);
258
259 err = mt7996_mcu_add_key(&dev->mt76, link, key,
260 MCU_WMWA_UNI_CMD(STA_REC_UPDATE),
261 &msta_link->wcid, cmd);
262
263 /* remove and add beacon in order to enable beacon protection */
264 if (cmd == SET_KEY && is_bigtk && link_conf->enable_beacon) {
265 mt7996_mcu_add_beacon(hw, vif, link_conf, false);
266 mt7996_mcu_add_beacon(hw, vif, link_conf, true);
267 }
268
269 return err;
270 }
271
272 struct mt7996_key_iter_data {
273 enum set_key_cmd cmd;
274 unsigned int link_id;
275 };
276
277 static void
278 mt7996_key_iter(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
279 struct ieee80211_sta *sta, struct ieee80211_key_conf *key,
280 void *data)
281 {
282 struct mt7996_key_iter_data *it = data;
283
284 if (sta)
285 return;
286
287 WARN_ON(mt7996_set_hw_key(hw, it->cmd, vif, NULL, it->link_id, key));
288 }
289
290 int mt7996_vif_link_add(struct mt76_phy *mphy, struct ieee80211_vif *vif,
291 struct ieee80211_bss_conf *link_conf,
292 struct mt76_vif_link *mlink)
293 {
294 struct mt7996_vif_link *link = container_of(mlink, struct mt7996_vif_link, mt76);
295 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
296 struct mt7996_sta_link *msta_link = &link->msta_link;
297 struct mt7996_phy *phy = mphy->priv;
298 struct mt7996_dev *dev = phy->dev;
299 u8 band_idx = phy->mt76->band_idx;
300 struct mt7996_key_iter_data it = {
301 .cmd = SET_KEY,
302 .link_id = link_conf->link_id,
303 };
304 int mld_idx, idx, ret;
305
306 mlink->idx = __ffs64(~dev->mt76.vif_mask);
307 if (mlink->idx >= mt7996_max_interface_num(dev))
308 return -ENOSPC;
309
310 idx = get_omac_idx(vif->type, phy->omac_mask);
311 if (idx < 0)
312 return -ENOSPC;
313
314 mld_idx = get_own_mld_idx(dev->mld_idx_mask, false);
315 if (mld_idx < 0)
316 return -ENOSPC;
317
318 link->mld_idx = mld_idx;
319 link->phy = phy;
320 mlink->omac_idx = idx;
321 mlink->band_idx = band_idx;
322 mlink->wmm_idx = vif->type == NL80211_IFTYPE_AP ? 0 : 3;
323 mlink->wcid = &msta_link->wcid;
324 mlink->wcid->offchannel = mlink->offchannel;
325
326 ret = mt7996_mcu_add_dev_info(phy, vif, link_conf, mlink, true);
327 if (ret)
328 return ret;
329
330 dev->mt76.vif_mask |= BIT_ULL(mlink->idx);
331 dev->mld_idx_mask |= BIT_ULL(link->mld_idx);
332 phy->omac_mask |= BIT_ULL(mlink->omac_idx);
333
334 idx = MT7996_WTBL_RESERVED - mlink->idx;
335
336 INIT_LIST_HEAD(&msta_link->rc_list);
337 msta_link->wcid.idx = idx;
338 msta_link->wcid.link_id = link_conf->link_id;
339 msta_link->wcid.link_valid = ieee80211_vif_is_mld(vif);
340 msta_link->wcid.tx_info |= MT_WCID_TX_INFO_SET;
341 mt76_wcid_init(&msta_link->wcid, band_idx);
342
343 mt7996_mac_wtbl_update(dev, idx,
344 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
345
346 if (vif->type != NL80211_IFTYPE_AP &&
347 (!mlink->omac_idx || mlink->omac_idx > 3))
348 vif->offload_flags = 0;
349
350 if (phy->mt76->chandef.chan->band != NL80211_BAND_2GHZ)
351 mlink->basic_rates_idx = MT7996_BASIC_RATES_TBL + 4;
352 else
353 mlink->basic_rates_idx = MT7996_BASIC_RATES_TBL;
354
355 mt7996_init_bitrate_mask(vif, link);
356
357 mt7996_mcu_add_bss_info(phy, vif, link_conf, mlink, msta_link, true);
358 /* defer the first STA_REC of BMC entry to BSS_CHANGED_BSSID for STA
359 * interface, since firmware only records BSSID when the entry is new
360 */
361 if (vif->type != NL80211_IFTYPE_STATION)
362 mt7996_mcu_add_sta(dev, link_conf, NULL, link, NULL,
363 CONN_STATE_PORT_SECURE, true);
364 rcu_assign_pointer(dev->mt76.wcid[idx], &msta_link->wcid);
365
366 ieee80211_iter_keys(mphy->hw, vif, mt7996_key_iter, &it);
367
368 if (vif->txq && !mlink->wcid->offchannel &&
369 mvif->mt76.deflink_id == IEEE80211_LINK_UNSPECIFIED) {
370 struct mt76_txq *mtxq = (struct mt76_txq *)vif->txq->drv_priv;
371
372 mvif->mt76.deflink_id = link_conf->link_id;
373 mtxq->wcid = idx;
374 }
375
376 return 0;
377 }
378
379 void mt7996_vif_link_remove(struct mt76_phy *mphy, struct ieee80211_vif *vif,
380 struct ieee80211_bss_conf *link_conf,
381 struct mt76_vif_link *mlink)
382 {
383 struct mt7996_vif_link *link = container_of(mlink, struct mt7996_vif_link, mt76);
384 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
385 struct mt7996_sta_link *msta_link = &link->msta_link;
386 struct mt7996_phy *phy = mphy->priv;
387 struct mt7996_dev *dev = phy->dev;
388 struct mt7996_key_iter_data it = {
389 .cmd = SET_KEY,
390 .link_id = link_conf->link_id,
391 };
392 int idx = msta_link->wcid.idx;
393
394 if (!mlink->wcid->offchannel)
395 ieee80211_iter_keys(mphy->hw, vif, mt7996_key_iter, &it);
396
397 mt7996_mcu_add_sta(dev, link_conf, NULL, link, NULL,
398 CONN_STATE_DISCONNECT, false);
399 mt7996_mcu_add_bss_info(phy, vif, link_conf, mlink, msta_link, false);
400
401 mt7996_mcu_add_dev_info(phy, vif, link_conf, mlink, false);
402
403 rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
404
405 if (vif->txq && !mlink->wcid->offchannel &&
406 mvif->mt76.deflink_id == link_conf->link_id) {
407 struct ieee80211_bss_conf *iter;
408 struct mt76_txq *mtxq;
409 unsigned int link_id;
410
411 mvif->mt76.deflink_id = IEEE80211_LINK_UNSPECIFIED;
412 mtxq = (struct mt76_txq *)vif->txq->drv_priv;
413 /* Primary link will be removed, look for a new one */
414 for_each_vif_active_link(vif, iter, link_id) {
415 struct mt7996_vif_link *link;
416
417 if (link_id == link_conf->link_id)
418 continue;
419
420 link = mt7996_vif_link(dev, vif, link_id);
421 if (!link)
422 continue;
423
424 mtxq->wcid = link->msta_link.wcid.idx;
425 mvif->mt76.deflink_id = link_id;
426 break;
427 }
428 }
429
430 dev->mt76.vif_mask &= ~BIT_ULL(mlink->idx);
431 dev->mld_idx_mask &= ~BIT_ULL(link->mld_idx);
432 phy->omac_mask &= ~BIT_ULL(mlink->omac_idx);
433
434 spin_lock_bh(&dev->mt76.sta_poll_lock);
435 if (!list_empty(&msta_link->wcid.poll_list))
436 list_del_init(&msta_link->wcid.poll_list);
437 spin_unlock_bh(&dev->mt76.sta_poll_lock);
438
439 mt76_wcid_cleanup(&dev->mt76, &msta_link->wcid);
440 }
441
442 static void mt7996_phy_set_rxfilter(struct mt7996_phy *phy)
443 {
444 struct mt7996_dev *dev = phy->dev;
445 u32 ctl_flags = MT_WF_RFCR1_DROP_ACK |
446 MT_WF_RFCR1_DROP_BF_POLL |
447 MT_WF_RFCR1_DROP_BA |
448 MT_WF_RFCR1_DROP_CFEND |
449 MT_WF_RFCR1_DROP_CFACK;
450 u32 filter = phy->rxfilter;
451
452 if (filter & MT_WF_RFCR_DROP_OTHER_UC) {
453 filter |= MT_WF_RFCR_DROP_CTS |
454 MT_WF_RFCR_DROP_RTS |
455 MT_WF_RFCR_DROP_CTL_RSV |
456 MT_WF_RFCR_DROP_FCSFAIL;
457 }
458
459 mt76_wr(dev, MT_WF_RFCR(phy->mt76->band_idx), filter);
460 if (filter & MT_WF_RFCR_DROP_CTL_RSV)
461 mt76_set(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags);
462 else
463 mt76_clear(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags);
464 }
465
466 static void mt7996_set_monitor(struct mt7996_phy *phy, bool enabled)
467 {
468 struct mt7996_dev *dev;
469
470 if (!phy)
471 return;
472
473 dev = phy->dev;
474
475 if (enabled == !(phy->rxfilter & MT_WF_RFCR_DROP_OTHER_UC))
476 return;
477
478 if (!enabled)
479 phy->rxfilter |= MT_WF_RFCR_DROP_OTHER_UC;
480 else
481 phy->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_UC;
482
483 mt76_rmw_field(dev, MT_DMA_DCR0(phy->mt76->band_idx),
484 MT_DMA_DCR0_RXD_G5_EN, enabled);
485 mt7996_phy_set_rxfilter(phy);
486 mt7996_mcu_set_sniffer_mode(phy, enabled);
487 }
488
489 static int mt7996_add_interface(struct ieee80211_hw *hw,
490 struct ieee80211_vif *vif)
491 {
492 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
493 struct wireless_dev *wdev = ieee80211_vif_to_wdev(vif);
494 struct mt7996_dev *dev = mt7996_hw_dev(hw);
495 int i, err = 0;
496
497 mutex_lock(&dev->mt76.mutex);
498
499 for (i = 0; i < MT7996_MAX_RADIOS; i++) {
500 struct mt7996_phy *phy = dev->radio_phy[i];
501
502 if (!phy || !(wdev->radio_mask & BIT(i)) ||
503 test_bit(MT76_STATE_RUNNING, &phy->mt76->state))
504 continue;
505
506 err = mt7996_run(phy);
507 if (err)
508 goto out;
509
510 if (vif->type == NL80211_IFTYPE_MONITOR)
511 mt7996_set_monitor(phy, true);
512 }
513
514 mt76_vif_init(vif, &mvif->mt76);
515
516 vif->offload_flags |= IEEE80211_OFFLOAD_ENCAP_4ADDR;
517 mvif->mt76.deflink_id = IEEE80211_LINK_UNSPECIFIED;
518
519 out:
520 mutex_unlock(&dev->mt76.mutex);
521
522 return err;
523 }
524
525 struct mt7996_radio_data {
526 u32 active_mask;
527 u32 monitor_mask;
528 };
529
530 static void mt7996_remove_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
531 {
532 struct wireless_dev *wdev = ieee80211_vif_to_wdev(vif);
533 struct mt7996_radio_data *rdata = data;
534
535 rdata->active_mask |= wdev->radio_mask;
536 if (vif->type == NL80211_IFTYPE_MONITOR)
537 rdata->monitor_mask |= wdev->radio_mask;
538 }
539
540 static void mt7996_remove_interface(struct ieee80211_hw *hw,
541 struct ieee80211_vif *vif)
542 {
543 struct mt7996_dev *dev = mt7996_hw_dev(hw);
544 struct mt7996_radio_data rdata = {};
545 int i;
546
547 ieee80211_iterate_active_interfaces_mtx(hw, 0, mt7996_remove_iter,
548 &rdata);
549 mt76_vif_cleanup(&dev->mt76, vif);
550
551 for (i = 0; i < MT7996_MAX_RADIOS; i++) {
552 struct mt7996_phy *phy = dev->radio_phy[i];
553
554 if (!phy)
555 continue;
556 if (!(rdata.monitor_mask & BIT(i)))
557 mt7996_set_monitor(phy, false);
558 if (!(rdata.active_mask & BIT(i)))
559 mt7996_stop_phy(phy);
560 }
561 }
562
563 int mt7996_set_channel(struct mt76_phy *mphy)
564 {
565 struct mt7996_phy *phy = mphy->priv;
566 int ret;
567
568 if (mphy->offchannel)
569 mt7996_mac_update_beacons(phy);
570
571 ret = mt7996_mcu_set_chan_info(phy, UNI_CHANNEL_SWITCH);
572 if (ret)
573 goto out;
574
575 ret = mt7996_mcu_set_chan_info(phy, UNI_CHANNEL_RX_PATH);
576 if (ret)
577 goto out;
578
579 ret = mt7996_mcu_set_txpower_sku(phy);
580 if (ret)
581 goto out;
582
583 ret = mt7996_dfs_init_radar_detector(phy);
584 mt7996_mac_cca_stats_reset(phy);
585
586 mt7996_mac_reset_counters(phy);
587 phy->noise = 0;
588 if (!mphy->offchannel)
589 mt7996_mac_update_beacons(phy);
590
591 out:
592 ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
593 MT7996_WATCHDOG_TIME);
594
595 return ret;
596 }
597
598 static int mt7996_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
599 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
600 struct ieee80211_key_conf *key)
601 {
602 struct mt7996_dev *dev = mt7996_hw_dev(hw);
603 unsigned int link_id;
604 unsigned long links;
605 int err = 0;
606
607 /* The hardware does not support per-STA RX GTK, fallback
608 * to software mode for these.
609 */
610 if ((vif->type == NL80211_IFTYPE_ADHOC ||
611 vif->type == NL80211_IFTYPE_MESH_POINT) &&
612 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
613 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
614 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
615 return -EOPNOTSUPP;
616
617 /* fall back to sw encryption for unsupported ciphers */
618 switch (key->cipher) {
619 case WLAN_CIPHER_SUITE_TKIP:
620 case WLAN_CIPHER_SUITE_CCMP:
621 case WLAN_CIPHER_SUITE_CCMP_256:
622 case WLAN_CIPHER_SUITE_GCMP:
623 case WLAN_CIPHER_SUITE_GCMP_256:
624 case WLAN_CIPHER_SUITE_SMS4:
625 break;
626 case WLAN_CIPHER_SUITE_AES_CMAC:
627 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
628 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
629 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
630 if (key->keyidx == 6 || key->keyidx == 7)
631 break;
632 fallthrough;
633 case WLAN_CIPHER_SUITE_WEP40:
634 case WLAN_CIPHER_SUITE_WEP104:
635 default:
636 return -EOPNOTSUPP;
637 }
638
639 mutex_lock(&dev->mt76.mutex);
640
641 if (key->link_id >= 0)
642 links = BIT(key->link_id);
643 else if (sta && sta->valid_links)
644 links = sta->valid_links;
645 else if (vif->valid_links)
646 links = vif->valid_links;
647 else
648 links = BIT(0);
649
650 for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
651 err = mt7996_set_hw_key(hw, cmd, vif, sta, link_id, key);
652 if (err)
653 break;
654 }
655 mutex_unlock(&dev->mt76.mutex);
656
657 return err;
658 }
659
660 static int mt7996_config(struct ieee80211_hw *hw, int radio_idx, u32 changed)
661 {
662 return 0;
663 }
664
665 static int
666 mt7996_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
667 unsigned int link_id, u16 queue,
668 const struct ieee80211_tx_queue_params *params)
669 {
670 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
671 struct mt7996_vif_link_info *link_info = &mvif->link_info[link_id];
672 static const u8 mq_to_aci[] = {
673 [IEEE80211_AC_VO] = 3,
674 [IEEE80211_AC_VI] = 2,
675 [IEEE80211_AC_BE] = 0,
676 [IEEE80211_AC_BK] = 1,
677 };
678
679 /* firmware uses access class index */
680 link_info->queue_params[mq_to_aci[queue]] = *params;
681 /* no need to update right away, we'll get BSS_CHANGED_QOS */
682
683 return 0;
684 }
685
686 static void mt7996_configure_filter(struct ieee80211_hw *hw,
687 unsigned int changed_flags,
688 unsigned int *total_flags,
689 u64 multicast)
690 {
691 struct mt7996_dev *dev = mt7996_hw_dev(hw);
692 struct mt7996_phy *phy;
693 u32 filter_mask = 0, filter_set = 0;
694 u32 flags = 0;
695
696 #define MT76_FILTER(_flag, _hw) do { \
697 flags |= *total_flags & FIF_##_flag; \
698 filter_mask |= (_hw); \
699 filter_set |= !(flags & FIF_##_flag) * (_hw); \
700 } while (0)
701
702 mutex_lock(&dev->mt76.mutex);
703
704 MT76_FILTER(OTHER_BSS, MT_WF_RFCR_DROP_OTHER_TIM |
705 MT_WF_RFCR_DROP_A3_MAC |
706 MT_WF_RFCR_DROP_A3_BSSID);
707
708 MT76_FILTER(FCSFAIL, MT_WF_RFCR_DROP_FCSFAIL);
709
710 MT76_FILTER(CONTROL, MT_WF_RFCR_DROP_CTS |
711 MT_WF_RFCR_DROP_RTS |
712 MT_WF_RFCR_DROP_CTL_RSV);
713
714 *total_flags = flags;
715
716 mt7996_for_each_phy(dev, phy) {
717 phy->rxfilter &= ~(MT_WF_RFCR_DROP_OTHER_BSS |
718 MT_WF_RFCR_DROP_OTHER_BEACON |
719 MT_WF_RFCR_DROP_FRAME_REPORT |
720 MT_WF_RFCR_DROP_PROBEREQ |
721 MT_WF_RFCR_DROP_MCAST_FILTERED |
722 MT_WF_RFCR_DROP_MCAST |
723 MT_WF_RFCR_DROP_BCAST |
724 MT_WF_RFCR_DROP_DUPLICATE |
725 MT_WF_RFCR_DROP_A2_BSSID |
726 MT_WF_RFCR_DROP_UNWANTED_CTL |
727 MT_WF_RFCR_DROP_STBC_MULTI |
728 filter_mask);
729 phy->rxfilter |= filter_set;
730 mt7996_phy_set_rxfilter(phy);
731 }
732
733 mutex_unlock(&dev->mt76.mutex);
734 }
735
736 static int
737 mt7996_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
738 unsigned int link_id, int *dbm)
739 {
740 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
741 struct mt7996_phy *phy = mt7996_vif_link_phy(&mvif->deflink);
742 struct mt7996_dev *dev = mt7996_hw_dev(hw);
743 struct wireless_dev *wdev;
744 int n_chains, delta, i;
745
746 if (!phy) {
747 wdev = ieee80211_vif_to_wdev(vif);
748 for (i = 0; i < hw->wiphy->n_radio; i++)
749 if (wdev->radio_mask & BIT(i))
750 phy = dev->radio_phy[i];
751
752 if (!phy)
753 return -EINVAL;
754 }
755
756 n_chains = hweight16(phy->mt76->chainmask);
757 delta = mt76_tx_power_path_delta(n_chains);
758 *dbm = DIV_ROUND_UP(phy->mt76->txpower_cur + delta, 2);
759
760 return 0;
761 }
762
763 static u8
764 mt7996_get_rates_table(struct mt7996_phy *phy, struct ieee80211_bss_conf *conf,
765 bool beacon, bool mcast)
766 {
767 struct mt7996_dev *dev = phy->dev;
768 struct mt76_vif_link *mvif = mt76_vif_conf_link(&dev->mt76, conf->vif, conf);
769 u16 rate;
770 u8 i, idx;
771
772 rate = mt76_connac2_mac_tx_rate_val(phy->mt76, conf, beacon, mcast);
773
774 if (beacon) {
775 /* odd index for driver, even index for firmware */
776 idx = MT7996_BEACON_RATES_TBL + 2 * phy->mt76->band_idx;
777 if (phy->beacon_rate != rate)
778 mt7996_mcu_set_fixed_rate_table(phy, idx, rate, beacon);
779
780 return idx;
781 }
782
783 idx = FIELD_GET(MT_TX_RATE_IDX, rate);
784 for (i = 0; i < ARRAY_SIZE(mt76_rates); i++)
785 if ((mt76_rates[i].hw_value & GENMASK(7, 0)) == idx)
786 return MT7996_BASIC_RATES_TBL + 2 * i;
787
788 return mvif->basic_rates_idx;
789 }
790
791 static void
792 mt7996_update_mu_group(struct ieee80211_hw *hw, struct mt7996_vif_link *link,
793 struct ieee80211_bss_conf *info)
794 {
795 struct mt7996_dev *dev = mt7996_hw_dev(hw);
796 u8 band = link->mt76.band_idx;
797 u32 *mu;
798
799 mu = (u32 *)info->mu_group.membership;
800 mt76_wr(dev, MT_WF_PHYRX_BAND_GID_TAB_VLD0(band), mu[0]);
801 mt76_wr(dev, MT_WF_PHYRX_BAND_GID_TAB_VLD1(band), mu[1]);
802
803 mu = (u32 *)info->mu_group.position;
804 mt76_wr(dev, MT_WF_PHYRX_BAND_GID_TAB_POS0(band), mu[0]);
805 mt76_wr(dev, MT_WF_PHYRX_BAND_GID_TAB_POS1(band), mu[1]);
806 mt76_wr(dev, MT_WF_PHYRX_BAND_GID_TAB_POS2(band), mu[2]);
807 mt76_wr(dev, MT_WF_PHYRX_BAND_GID_TAB_POS3(band), mu[3]);
808 }
809
810 static void
811 mt7996_vif_cfg_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
812 u64 changed)
813 {
814 struct mt7996_dev *dev = mt7996_hw_dev(hw);
815
816 mutex_lock(&dev->mt76.mutex);
817
818 if ((changed & BSS_CHANGED_ASSOC) && vif->cfg.assoc) {
819 struct ieee80211_bss_conf *link_conf;
820 unsigned long link_id;
821
822 for_each_vif_active_link(vif, link_conf, link_id) {
823 struct mt7996_vif_link *link;
824
825 link = mt7996_vif_link(dev, vif, link_id);
826 if (!link)
827 continue;
828
829 if (!link->phy)
830 continue;
831
832 mt7996_mcu_add_bss_info(link->phy, vif, link_conf,
833 &link->mt76, &link->msta_link,
834 true);
835 mt7996_mcu_add_sta(dev, link_conf, NULL, link, NULL,
836 CONN_STATE_PORT_SECURE,
837 !!(changed & BSS_CHANGED_BSSID));
838 }
839 }
840
841 mutex_unlock(&dev->mt76.mutex);
842 }
843
844 static void
845 mt7996_link_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
846 struct ieee80211_bss_conf *info, u64 changed)
847 {
848 struct mt7996_dev *dev = mt7996_hw_dev(hw);
849 struct mt7996_vif_link *link;
850 struct mt7996_phy *phy;
851 struct mt76_phy *mphy;
852
853 mutex_lock(&dev->mt76.mutex);
854
855 link = mt7996_vif_conf_link(dev, vif, info);
856 if (!link)
857 goto out;
858
859 mphy = mt76_vif_link_phy(&link->mt76);
860 if (!mphy)
861 goto out;
862
863 phy = mphy->priv;
864
865 /* station mode uses BSSID to map the wlan entry to a peer,
866 * and then peer references bss_info_rfch to set bandwidth cap.
867 */
868 if ((changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid)) ||
869 (changed & BSS_CHANGED_BEACON_ENABLED && info->enable_beacon)) {
870 mt7996_mcu_add_bss_info(phy, vif, info, &link->mt76,
871 &link->msta_link, true);
872 mt7996_mcu_add_sta(dev, info, NULL, link, NULL,
873 CONN_STATE_PORT_SECURE,
874 !!(changed & BSS_CHANGED_BSSID));
875 }
876
877 if (changed & BSS_CHANGED_ERP_SLOT) {
878 int slottime = info->use_short_slot ? 9 : 20;
879
880 if (slottime != phy->slottime) {
881 phy->slottime = slottime;
882 mt7996_mcu_set_timing(phy, vif, info);
883 }
884 }
885
886 if (changed & BSS_CHANGED_MCAST_RATE)
887 link->mt76.mcast_rates_idx =
888 mt7996_get_rates_table(phy, info, false, true);
889
890 if (changed & BSS_CHANGED_BASIC_RATES)
891 link->mt76.basic_rates_idx =
892 mt7996_get_rates_table(phy, info, false, false);
893
894 /* ensure that enable txcmd_mode after bss_info */
895 if (changed & (BSS_CHANGED_QOS | BSS_CHANGED_BEACON_ENABLED))
896 mt7996_mcu_set_tx(dev, vif, info);
897
898 if (changed & BSS_CHANGED_HE_OBSS_PD)
899 mt7996_mcu_add_obss_spr(phy, link, &info->he_obss_pd);
900
901 if (changed & BSS_CHANGED_HE_BSS_COLOR) {
902 if ((vif->type == NL80211_IFTYPE_AP &&
903 link->mt76.omac_idx <= HW_BSSID_MAX) ||
904 vif->type == NL80211_IFTYPE_STATION)
905 mt7996_mcu_update_bss_color(dev, &link->mt76,
906 &info->he_bss_color);
907 }
908
909 if (changed & (BSS_CHANGED_BEACON |
910 BSS_CHANGED_BEACON_ENABLED)) {
911 link->mt76.beacon_rates_idx =
912 mt7996_get_rates_table(phy, info, true, false);
913
914 mt7996_mcu_add_beacon(hw, vif, info, info->enable_beacon);
915 }
916
917 if (changed & (BSS_CHANGED_UNSOL_BCAST_PROBE_RESP |
918 BSS_CHANGED_FILS_DISCOVERY))
919 mt7996_mcu_beacon_inband_discov(dev, info, link, changed);
920
921 if (changed & BSS_CHANGED_MU_GROUPS)
922 mt7996_update_mu_group(hw, link, info);
923
924 if (changed & BSS_CHANGED_TXPOWER &&
925 info->txpower != phy->txpower) {
926 phy->txpower = info->txpower;
927 mt7996_mcu_set_txpower_sku(phy);
928 }
929
930 out:
931 mutex_unlock(&dev->mt76.mutex);
932 }
933
934 static void
935 mt7996_channel_switch_beacon(struct ieee80211_hw *hw,
936 struct ieee80211_vif *vif,
937 struct cfg80211_chan_def *chandef)
938 {
939 struct mt7996_dev *dev = mt7996_hw_dev(hw);
940
941 mutex_lock(&dev->mt76.mutex);
942 mt7996_mcu_add_beacon(hw, vif, &vif->bss_conf, vif->bss_conf.enable_beacon);
943 mutex_unlock(&dev->mt76.mutex);
944 }
945
946 static int
947 mt7996_post_channel_switch(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
948 struct ieee80211_bss_conf *link_conf)
949 {
950 struct cfg80211_chan_def *chandef = &link_conf->chanreq.oper;
951 struct mt7996_dev *dev = mt7996_hw_dev(hw);
952 struct mt7996_phy *phy = mt7996_band_phy(dev, chandef->chan->band);
953 int ret;
954
955 mutex_lock(&dev->mt76.mutex);
956
957 ret = mt7996_mcu_rdd_resume_tx(phy);
958
959 mutex_unlock(&dev->mt76.mutex);
960
961 return ret;
962 }
963
964 static void
965 mt7996_sta_init_txq_wcid(struct ieee80211_sta *sta, int idx)
966 {
967 int i;
968
969 for (i = 0; i < ARRAY_SIZE(sta->txq); i++) {
970 struct mt76_txq *mtxq;
971
972 if (!sta->txq[i])
973 continue;
974
975 mtxq = (struct mt76_txq *)sta->txq[i]->drv_priv;
976 mtxq->wcid = idx;
977 }
978 }
979
980 static int
981 mt7996_mac_sta_init_link(struct mt7996_dev *dev,
982 struct ieee80211_bss_conf *link_conf,
983 struct ieee80211_link_sta *link_sta,
984 struct mt7996_vif_link *link, unsigned int link_id)
985 {
986 struct ieee80211_sta *sta = link_sta->sta;
987 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
988 struct mt7996_phy *phy = link->phy;
989 struct mt7996_sta_link *msta_link;
990 int idx;
991
992 idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7996_WTBL_STA);
993 if (idx < 0)
994 return -ENOSPC;
995
996 if (msta->deflink_id == IEEE80211_LINK_UNSPECIFIED) {
997 msta_link = &msta->deflink;
998 msta->deflink_id = link_id;
999 msta->seclink_id = msta->deflink_id;
1000 mt7996_sta_init_txq_wcid(sta, idx);
1001 } else {
1002 msta_link = kzalloc_obj(*msta_link);
1003 if (!msta_link)
1004 return -ENOMEM;
1005
1006 if (msta->seclink_id == msta->deflink_id &&
1007 (sta->valid_links & ~BIT(msta->deflink_id)))
1008 msta->seclink_id = __ffs(sta->valid_links &
1009 ~BIT(msta->deflink_id));
1010 }
1011
1012 INIT_LIST_HEAD(&msta_link->rc_list);
1013 INIT_LIST_HEAD(&msta_link->wcid.poll_list);
1014 msta_link->sta = msta;
1015 msta_link->wcid.sta = 1;
1016 msta_link->wcid.idx = idx;
1017 msta_link->wcid.link_id = link_id;
1018 msta_link->wcid.link_valid = !!sta->valid_links;
1019 msta_link->wcid.def_wcid = &msta->deflink.wcid;
1020
1021 ewma_avg_signal_init(&msta_link->avg_ack_signal);
1022 ewma_signal_init(&msta_link->wcid.rssi);
1023
1024 rcu_assign_pointer(msta->link[link_id], msta_link);
1025
1026 mt7996_mac_wtbl_update(dev, idx, MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
1027 mt7996_mcu_add_sta(dev, link_conf, link_sta, link, msta_link,
1028 CONN_STATE_DISCONNECT, true);
1029
1030 rcu_assign_pointer(dev->mt76.wcid[idx], &msta_link->wcid);
1031 mt76_wcid_init(&msta_link->wcid, phy->mt76->band_idx);
1032
1033 return 0;
1034 }
1035
1036 void mt7996_mac_sta_deinit_link(struct mt7996_dev *dev,
1037 struct mt7996_sta_link *msta_link)
1038 {
1039 spin_lock_bh(&dev->mt76.sta_poll_lock);
1040 if (!list_empty(&msta_link->wcid.poll_list))
1041 list_del_init(&msta_link->wcid.poll_list);
1042 if (!list_empty(&msta_link->rc_list))
1043 list_del_init(&msta_link->rc_list);
1044 spin_unlock_bh(&dev->mt76.sta_poll_lock);
1045
1046 rcu_assign_pointer(dev->mt76.wcid[msta_link->wcid.idx], NULL);
1047 mt76_wcid_cleanup(&dev->mt76, &msta_link->wcid);
1048 mt76_wcid_mask_clear(dev->mt76.wcid_mask, msta_link->wcid.idx);
1049 }
1050
1051 static void
1052 mt7996_mac_sta_remove_links(struct mt7996_dev *dev, struct ieee80211_vif *vif,
1053 struct ieee80211_sta *sta, unsigned long links)
1054 {
1055 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
1056 struct mt76_dev *mdev = &dev->mt76;
1057 unsigned int link_id;
1058
1059 for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
1060 struct mt7996_sta_link *msta_link = NULL;
1061 struct mt7996_phy *phy;
1062
1063 msta_link = rcu_replace_pointer(msta->link[link_id], msta_link,
1064 lockdep_is_held(&mdev->mutex));
1065 if (!msta_link)
1066 continue;
1067
1068 mt7996_mac_wtbl_update(dev, msta_link->wcid.idx,
1069 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
1070 mt7996_mac_sta_deinit_link(dev, msta_link);
1071
1072 phy = __mt7996_phy(dev, msta_link->wcid.phy_idx);
1073 if (phy)
1074 phy->mt76->num_sta--;
1075
1076 if (msta->deflink_id == link_id) {
1077 msta->deflink_id = IEEE80211_LINK_UNSPECIFIED;
1078 if (msta->seclink_id == link_id) {
1079 /* no secondary link available */
1080 msta->seclink_id = msta->deflink_id;
1081 } else {
1082 struct mt7996_sta_link *msta_seclink;
1083
1084 /* switch to the secondary link */
1085 msta_seclink = mt76_dereference(
1086 msta->link[msta->seclink_id],
1087 mdev);
1088 if (msta_seclink) {
1089 msta->deflink_id = msta->seclink_id;
1090 mt7996_sta_init_txq_wcid(sta,
1091 msta_seclink->wcid.idx);
1092 }
1093 }
1094 } else if (msta->seclink_id == link_id) {
1095 msta->seclink_id = msta->deflink_id;
1096 }
1097
1098 if (msta_link != &msta->deflink)
1099 kfree_rcu(msta_link, rcu_head);
1100 }
1101 }
1102
1103 static int
1104 mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif,
1105 struct ieee80211_sta *sta, unsigned long new_links)
1106 {
1107 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
1108 unsigned int link_id;
1109 int err = 0;
1110
1111 for_each_set_bit(link_id, &new_links, IEEE80211_MLD_MAX_NUM_LINKS) {
1112 struct ieee80211_bss_conf *link_conf;
1113 struct ieee80211_link_sta *link_sta;
1114 struct mt7996_vif_link *link;
1115 struct mt76_phy *mphy;
1116
1117 if (rcu_access_pointer(msta->link[link_id]))
1118 continue;
1119
1120 link_conf = link_conf_dereference_protected(vif, link_id);
1121 if (!link_conf) {
1122 err = -EINVAL;
1123 goto error_unlink;
1124 }
1125
1126 link = mt7996_vif_link(dev, vif, link_id);
1127 if (!link) {
1128 err = -EINVAL;
1129 goto error_unlink;
1130 }
1131
1132 link_sta = link_sta_dereference_protected(sta, link_id);
1133 if (!link_sta) {
1134 err = -EINVAL;
1135 goto error_unlink;
1136 }
1137
1138 mphy = mt76_vif_link_phy(&link->mt76);
1139 if (!mphy) {
1140 err = -EINVAL;
1141 goto error_unlink;
1142 }
1143
1144 err = mt7996_mac_sta_init_link(dev, link_conf, link_sta, link,
1145 link_id);
1146 if (err)
1147 goto error_unlink;
1148
1149 mphy->num_sta++;
1150 }
1151
1152 return 0;
1153
1154 error_unlink:
1155 mt7996_mac_sta_remove_links(dev, vif, sta, new_links);
1156
1157 return err;
1158 }
1159
1160 static int
1161 mt7996_mac_sta_change_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1162 struct ieee80211_sta *sta, u16 old_links,
1163 u16 new_links)
1164 {
1165 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1166 unsigned long add = new_links & ~old_links;
1167 unsigned long rem = old_links & ~new_links;
1168 int ret;
1169
1170 mutex_lock(&dev->mt76.mutex);
1171
1172 mt7996_mac_sta_remove_links(dev, vif, sta, rem);
1173 ret = mt7996_mac_sta_add_links(dev, vif, sta, add);
1174
1175 mutex_unlock(&dev->mt76.mutex);
1176
1177 return ret;
1178 }
1179
1180 static int
1181 mt7996_mac_sta_add(struct mt7996_dev *dev, struct ieee80211_vif *vif,
1182 struct ieee80211_sta *sta)
1183 {
1184 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
1185 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
1186 unsigned long links = sta->valid_links ? sta->valid_links : BIT(0);
1187 int err;
1188
1189 mutex_lock(&dev->mt76.mutex);
1190
1191 msta->deflink_id = IEEE80211_LINK_UNSPECIFIED;
1192 msta->seclink_id = IEEE80211_LINK_UNSPECIFIED;
1193 msta->vif = mvif;
1194 err = mt7996_mac_sta_add_links(dev, vif, sta, links);
1195
1196 mutex_unlock(&dev->mt76.mutex);
1197
1198 return err;
1199 }
1200
1201 static int
1202 mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif,
1203 struct ieee80211_sta *sta, enum mt76_sta_event ev)
1204 {
1205 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
1206 unsigned long links = sta->valid_links;
1207 struct ieee80211_link_sta *link_sta;
1208 unsigned int link_id;
1209 int err = 0;
1210
1211 mutex_lock(&dev->mt76.mutex);
1212
1213 for_each_sta_active_link(vif, sta, link_sta, link_id) {
1214 struct ieee80211_bss_conf *link_conf;
1215 struct mt7996_sta_link *msta_link;
1216 struct mt7996_vif_link *link;
1217 int i;
1218
1219 link_conf = link_conf_dereference_protected(vif, link_id);
1220 if (!link_conf)
1221 continue;
1222
1223 link = mt7996_vif_link(dev, vif, link_id);
1224 if (!link)
1225 continue;
1226
1227 msta_link = mt76_dereference(msta->link[link_id], &dev->mt76);
1228 if (!msta_link)
1229 continue;
1230
1231 switch (ev) {
1232 case MT76_STA_EVENT_ASSOC:
1233 err = mt7996_mcu_add_sta(dev, link_conf, link_sta,
1234 link, msta_link,
1235 CONN_STATE_CONNECT, true);
1236 if (err)
1237 goto unlock;
1238
1239 err = mt7996_mcu_add_rate_ctrl(dev, msta_link->sta, vif,
1240 link_id, false);
1241 if (err)
1242 goto unlock;
1243
1244 msta_link->wcid.tx_info |= MT_WCID_TX_INFO_SET;
1245 break;
1246 case MT76_STA_EVENT_AUTHORIZE:
1247 err = mt7996_mcu_add_sta(dev, link_conf, link_sta,
1248 link, msta_link,
1249 CONN_STATE_PORT_SECURE, false);
1250 if (err)
1251 goto unlock;
1252 break;
1253 case MT76_STA_EVENT_DISASSOC:
1254 for (i = 0; i < ARRAY_SIZE(msta_link->twt.flow); i++)
1255 mt7996_mac_twt_teardown_flow(dev, link,
1256 msta_link, i);
1257
1258 if (!sta->mlo)
1259 mt7996_mcu_add_sta(dev, link_conf, link_sta,
1260 link, msta_link,
1261 CONN_STATE_DISCONNECT, false);
1262 else if (sta->mlo && links == BIT(link_id)) /* last link */
1263 mt7996_mcu_teardown_mld_sta(dev, link,
1264 msta_link);
1265 msta_link->wcid.sta_disabled = 1;
1266 msta_link->wcid.sta = 0;
1267 links = links & ~BIT(link_id);
1268 break;
1269 }
1270 }
1271 unlock:
1272 mutex_unlock(&dev->mt76.mutex);
1273
1274 return err;
1275 }
1276
1277 static void
1278 mt7996_mac_sta_remove(struct mt7996_dev *dev, struct ieee80211_vif *vif,
1279 struct ieee80211_sta *sta)
1280 {
1281 unsigned long links = sta->valid_links ? sta->valid_links : BIT(0);
1282
1283 mutex_lock(&dev->mt76.mutex);
1284 mt7996_mac_sta_remove_links(dev, vif, sta, links);
1285 mutex_unlock(&dev->mt76.mutex);
1286 }
1287
1288 static void
1289 mt7996_set_active_links(struct ieee80211_vif *vif)
1290 {
1291 u16 active_links;
1292
1293 if (vif->type != NL80211_IFTYPE_STATION)
1294 return;
1295
1296 if (!ieee80211_vif_is_mld(vif))
1297 return;
1298
1299 active_links = mt76_select_links(vif, MT7996_MAX_RADIOS);
1300 if (hweight16(active_links) < 2)
1301 return;
1302
1303 ieee80211_set_active_links_async(vif, active_links);
1304 }
1305
1306 static int
1307 mt7996_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1308 struct ieee80211_sta *sta, enum ieee80211_sta_state old_state,
1309 enum ieee80211_sta_state new_state)
1310 {
1311 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1312 enum mt76_sta_event ev;
1313
1314 if (old_state == IEEE80211_STA_NOTEXIST &&
1315 new_state == IEEE80211_STA_NONE)
1316 return mt7996_mac_sta_add(dev, vif, sta);
1317
1318 if (old_state == IEEE80211_STA_NONE &&
1319 new_state == IEEE80211_STA_NOTEXIST)
1320 mt7996_mac_sta_remove(dev, vif, sta);
1321
1322 if (old_state == IEEE80211_STA_AUTH &&
1323 new_state == IEEE80211_STA_ASSOC) {
1324 mt7996_set_active_links(vif);
1325 ev = MT76_STA_EVENT_ASSOC;
1326 } else if (old_state == IEEE80211_STA_ASSOC &&
1327 new_state == IEEE80211_STA_AUTHORIZED) {
1328 ev = MT76_STA_EVENT_AUTHORIZE;
1329 } else if (old_state == IEEE80211_STA_ASSOC &&
1330 new_state == IEEE80211_STA_AUTH) {
1331 ev = MT76_STA_EVENT_DISASSOC;
1332 } else {
1333 return 0;
1334 }
1335
1336 return mt7996_mac_sta_event(dev, vif, sta, ev);
1337 }
1338
1339 static void mt7996_tx(struct ieee80211_hw *hw,
1340 struct ieee80211_tx_control *control,
1341 struct sk_buff *skb)
1342 {
1343 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1344 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1345 struct ieee80211_sta *sta = control->sta;
1346 struct mt7996_sta *msta = sta ? (void *)sta->drv_priv : NULL;
1347 struct mt76_phy *mphy = hw->priv;
1348 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1349 struct ieee80211_vif *vif = info->control.vif;
1350 struct mt7996_vif *mvif = vif ? (void *)vif->drv_priv : NULL;
1351 struct mt76_wcid *wcid = &dev->mt76.global_wcid;
1352 u8 link_id = u32_get_bits(info->control.flags,
1353 IEEE80211_TX_CTRL_MLO_LINK);
1354
1355 rcu_read_lock();
1356
1357 /* Use primary link_id if the value from mac80211 is set to
1358 * IEEE80211_LINK_UNSPECIFIED.
1359 */
1360 if (link_id == IEEE80211_LINK_UNSPECIFIED) {
1361 if (msta)
1362 link_id = msta->deflink_id;
1363 else if (mvif)
1364 link_id = mvif->mt76.deflink_id;
1365 }
1366
1367 if (vif && ieee80211_vif_is_mld(vif)) {
1368 struct ieee80211_bss_conf *link_conf;
1369
1370 if (msta) {
1371 struct ieee80211_link_sta *link_sta;
1372
1373 link_sta = rcu_dereference(sta->link[link_id]);
1374 if (!link_sta)
1375 link_sta = rcu_dereference(sta->link[msta->deflink_id]);
1376
1377 if (link_sta) {
1378 memcpy(hdr->addr1, link_sta->addr, ETH_ALEN);
1379 if (ether_addr_equal(sta->addr, hdr->addr3))
1380 memcpy(hdr->addr3, link_sta->addr, ETH_ALEN);
1381 }
1382 }
1383
1384 link_conf = rcu_dereference(vif->link_conf[link_id]);
1385 if (link_conf) {
1386 memcpy(hdr->addr2, link_conf->addr, ETH_ALEN);
1387 if (ether_addr_equal(vif->addr, hdr->addr3))
1388 memcpy(hdr->addr3, link_conf->addr, ETH_ALEN);
1389 }
1390 }
1391
1392 if (mvif) {
1393 struct mt76_vif_link *mlink;
1394
1395 mlink = rcu_dereference(mvif->mt76.link[link_id]);
1396 if (mlink && mlink->wcid)
1397 wcid = mlink->wcid;
1398
1399 if (mvif->mt76.roc_phy &&
1400 (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN)) {
1401 mphy = mvif->mt76.roc_phy;
1402 if (mphy->roc_link)
1403 wcid = mphy->roc_link->wcid;
1404 } else if (mlink) {
1405 mphy = mt76_vif_link_phy(mlink);
1406 }
1407 }
1408
1409 if (!mphy) {
1410 ieee80211_free_txskb(hw, skb);
1411 goto unlock;
1412 }
1413
1414 if (msta) {
1415 struct mt7996_sta_link *msta_link;
1416
1417 msta_link = rcu_dereference(msta->link[link_id]);
1418 if (msta_link)
1419 wcid = &msta_link->wcid;
1420 }
1421 mt76_tx(mphy, control->sta, wcid, skb);
1422 unlock:
1423 rcu_read_unlock();
1424 }
1425
1426 static int mt7996_set_rts_threshold(struct ieee80211_hw *hw, int radio_idx,
1427 u32 val)
1428 {
1429 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1430 int i, ret = 0;
1431
1432 mutex_lock(&dev->mt76.mutex);
1433
1434 for (i = 0; i < hw->wiphy->n_radio; i++) {
1435 struct mt7996_phy *phy = dev->radio_phy[i];
1436
1437 ret = mt7996_mcu_set_rts_thresh(phy, val);
1438 if (ret)
1439 break;
1440 }
1441
1442 mutex_unlock(&dev->mt76.mutex);
1443
1444 return ret;
1445 }
1446
1447 static int
1448 mt7996_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1449 struct ieee80211_ampdu_params *params)
1450 {
1451 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1452 struct ieee80211_sta *sta = params->sta;
1453 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
1454 struct ieee80211_txq *txq = sta->txq[params->tid];
1455 u16 tid = params->tid;
1456 u16 ssn = params->ssn;
1457 struct mt76_txq *mtxq;
1458 int ret = 0;
1459
1460 if (!txq)
1461 return -EINVAL;
1462
1463 mtxq = (struct mt76_txq *)txq->drv_priv;
1464
1465 mutex_lock(&dev->mt76.mutex);
1466
1467 switch (params->action) {
1468 case IEEE80211_AMPDU_RX_START:
1469 /* Since packets belonging to the same TID can be split over
1470 * multiple links, store the AMPDU state for reordering in the
1471 * primary link
1472 */
1473 mt76_rx_aggr_start(&dev->mt76, &msta->deflink.wcid, tid,
1474 ssn, params->buf_size);
1475 ret = mt7996_mcu_add_rx_ba(dev, params, vif, true);
1476 break;
1477 case IEEE80211_AMPDU_RX_STOP:
1478 mt76_rx_aggr_stop(&dev->mt76, &msta->deflink.wcid, tid);
1479 ret = mt7996_mcu_add_rx_ba(dev, params, vif, false);
1480 break;
1481 case IEEE80211_AMPDU_TX_OPERATIONAL:
1482 mtxq->aggr = true;
1483 mtxq->send_bar = false;
1484 ret = mt7996_mcu_add_tx_ba(dev, params, vif, true);
1485 break;
1486 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1487 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1488 mtxq->aggr = false;
1489 clear_bit(tid, &msta->deflink.wcid.ampdu_state);
1490 ret = mt7996_mcu_add_tx_ba(dev, params, vif, false);
1491 break;
1492 case IEEE80211_AMPDU_TX_START:
1493 set_bit(tid, &msta->deflink.wcid.ampdu_state);
1494 ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;
1495 break;
1496 case IEEE80211_AMPDU_TX_STOP_CONT:
1497 mtxq->aggr = false;
1498 clear_bit(tid, &msta->deflink.wcid.ampdu_state);
1499 ret = mt7996_mcu_add_tx_ba(dev, params, vif, false);
1500 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1501 break;
1502 }
1503
1504 mutex_unlock(&dev->mt76.mutex);
1505
1506 return ret;
1507 }
1508
1509 static int
1510 mt7996_get_stats(struct ieee80211_hw *hw,
1511 struct ieee80211_low_level_stats *stats)
1512 {
1513 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1514 int i;
1515
1516 mutex_lock(&dev->mt76.mutex);
1517
1518 memset(stats, 0, sizeof(*stats));
1519 for (i = 0; i < hw->wiphy->n_radio; i++) {
1520 struct mt7996_phy *phy = dev->radio_phy[i];
1521 struct mt76_mib_stats *mib = &phy->mib;
1522
1523 stats->dot11RTSSuccessCount += mib->rts_cnt;
1524 stats->dot11RTSFailureCount += mib->rts_retries_cnt;
1525 stats->dot11FCSErrorCount += mib->fcs_err_cnt;
1526 stats->dot11ACKFailureCount += mib->ack_fail_cnt;
1527 }
1528
1529 mutex_unlock(&dev->mt76.mutex);
1530
1531 return 0;
1532 }
1533
1534 u64 __mt7996_get_tsf(struct ieee80211_hw *hw, struct mt7996_vif_link *link)
1535 {
1536 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1537 struct mt7996_phy *phy = link->phy;
1538 union {
1539 u64 t64;
1540 u32 t32[2];
1541 } tsf;
1542 u16 n;
1543
1544 if (!phy)
1545 return 0;
1546
1547 lockdep_assert_held(&dev->mt76.mutex);
1548
1549 n = link->mt76.omac_idx > HW_BSSID_MAX ? HW_BSSID_0
1550 : link->mt76.omac_idx;
1551 /* TSF software read */
1552 mt76_rmw(dev, MT_LPON_TCR(phy->mt76->band_idx, n), MT_LPON_TCR_SW_MODE,
1553 MT_LPON_TCR_SW_READ);
1554 tsf.t32[0] = mt76_rr(dev, MT_LPON_UTTR0(phy->mt76->band_idx));
1555 tsf.t32[1] = mt76_rr(dev, MT_LPON_UTTR1(phy->mt76->band_idx));
1556
1557 return tsf.t64;
1558 }
1559
1560 static u64
1561 mt7996_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1562 {
1563 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
1564 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1565 u64 ret;
1566
1567 mutex_lock(&dev->mt76.mutex);
1568 ret = __mt7996_get_tsf(hw, &mvif->deflink);
1569 mutex_unlock(&dev->mt76.mutex);
1570
1571 return ret;
1572 }
1573
1574 static void
1575 mt7996_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1576 u64 timestamp)
1577 {
1578 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
1579 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1580 struct mt7996_vif_link *link;
1581 struct mt7996_phy *phy;
1582 union {
1583 u64 t64;
1584 u32 t32[2];
1585 } tsf = { .t64 = timestamp, };
1586 u16 n;
1587
1588 mutex_lock(&dev->mt76.mutex);
1589
1590 link = mt7996_vif_link(dev, vif, mvif->mt76.deflink_id);
1591 if (!link)
1592 goto unlock;
1593
1594 n = link->mt76.omac_idx > HW_BSSID_MAX ? HW_BSSID_0
1595 : link->mt76.omac_idx;
1596 phy = link->phy;
1597 if (!phy)
1598 goto unlock;
1599
1600 mt76_wr(dev, MT_LPON_UTTR0(phy->mt76->band_idx), tsf.t32[0]);
1601 mt76_wr(dev, MT_LPON_UTTR1(phy->mt76->band_idx), tsf.t32[1]);
1602 /* TSF software overwrite */
1603 mt76_rmw(dev, MT_LPON_TCR(phy->mt76->band_idx, n), MT_LPON_TCR_SW_MODE,
1604 MT_LPON_TCR_SW_WRITE);
1605
1606 unlock:
1607 mutex_unlock(&dev->mt76.mutex);
1608 }
1609
1610 static void
1611 mt7996_offset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1612 s64 timestamp)
1613 {
1614 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
1615 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1616 struct mt7996_vif_link *link;
1617 struct mt7996_phy *phy;
1618 union {
1619 u64 t64;
1620 u32 t32[2];
1621 } tsf = { .t64 = timestamp, };
1622 u16 n;
1623
1624 mutex_lock(&dev->mt76.mutex);
1625
1626 link = mt7996_vif_link(dev, vif, mvif->mt76.deflink_id);
1627 if (!link)
1628 goto unlock;
1629
1630 phy = link->phy;
1631 if (!phy)
1632 goto unlock;
1633
1634 n = link->mt76.omac_idx > HW_BSSID_MAX ? HW_BSSID_0
1635 : link->mt76.omac_idx;
1636 mt76_wr(dev, MT_LPON_UTTR0(phy->mt76->band_idx), tsf.t32[0]);
1637 mt76_wr(dev, MT_LPON_UTTR1(phy->mt76->band_idx), tsf.t32[1]);
1638 /* TSF software adjust*/
1639 mt76_rmw(dev, MT_LPON_TCR(phy->mt76->band_idx, n), MT_LPON_TCR_SW_MODE,
1640 MT_LPON_TCR_SW_ADJUST);
1641
1642 unlock:
1643 mutex_unlock(&dev->mt76.mutex);
1644 }
1645
1646 static void
1647 mt7996_set_coverage_class(struct ieee80211_hw *hw, int radio_idx,
1648 s16 coverage_class)
1649 {
1650 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1651 struct mt7996_phy *phy;
1652
1653 mutex_lock(&dev->mt76.mutex);
1654 mt7996_for_each_phy(dev, phy) {
1655 phy->coverage_class = max_t(s16, coverage_class, 0);
1656 mt7996_mac_set_coverage_class(phy);
1657 }
1658 mutex_unlock(&dev->mt76.mutex);
1659 }
1660
1661 static int
1662 mt7996_set_antenna(struct ieee80211_hw *hw, int radio_idx,
1663 u32 tx_ant, u32 rx_ant)
1664 {
1665 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1666 int i;
1667
1668 if (tx_ant != rx_ant)
1669 return -EINVAL;
1670
1671 for (i = 0; i < hw->wiphy->n_radio; i++) {
1672 struct mt7996_phy *phy = dev->radio_phy[i];
1673
1674 if (!(tx_ant & phy->orig_chainmask))
1675 return -EINVAL;
1676 }
1677
1678 mutex_lock(&dev->mt76.mutex);
1679
1680 for (i = 0; i < hw->wiphy->n_radio; i++) {
1681 struct mt7996_phy *phy = dev->radio_phy[i];
1682 u8 band_idx = phy->mt76->band_idx;
1683 u8 shift = dev->chainshift[band_idx];
1684
1685 phy->mt76->chainmask = tx_ant & phy->orig_chainmask;
1686 phy->mt76->antenna_mask = (phy->mt76->chainmask >> shift) &
1687 phy->orig_antenna_mask;
1688
1689 mt76_set_stream_caps(phy->mt76, true);
1690 mt7996_set_stream_vht_txbf_caps(phy);
1691 mt7996_set_stream_he_eht_caps(phy);
1692 mt7996_mcu_set_txpower_sku(phy);
1693 }
1694
1695 mutex_unlock(&dev->mt76.mutex);
1696
1697 return 0;
1698 }
1699
1700 static void mt7996_sta_statistics(struct ieee80211_hw *hw,
1701 struct ieee80211_vif *vif,
1702 struct ieee80211_sta *sta,
1703 struct station_info *sinfo)
1704 {
1705 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1706 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
1707 struct mt7996_sta_link *msta_link = &msta->deflink;
1708 struct rate_info *txrate = &msta_link->wcid.rate;
1709
1710 if (txrate->legacy || txrate->flags) {
1711 if (txrate->legacy) {
1712 sinfo->txrate.legacy = txrate->legacy;
1713 } else {
1714 sinfo->txrate.mcs = txrate->mcs;
1715 sinfo->txrate.nss = txrate->nss;
1716 sinfo->txrate.bw = txrate->bw;
1717 sinfo->txrate.he_gi = txrate->he_gi;
1718 sinfo->txrate.he_dcm = txrate->he_dcm;
1719 sinfo->txrate.he_ru_alloc = txrate->he_ru_alloc;
1720 sinfo->txrate.eht_gi = txrate->eht_gi;
1721 }
1722 sinfo->txrate.flags = txrate->flags;
1723 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
1724 }
1725 sinfo->txrate.flags = txrate->flags;
1726 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
1727
1728 sinfo->tx_failed = msta_link->wcid.stats.tx_failed;
1729 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
1730
1731 sinfo->tx_retries = msta_link->wcid.stats.tx_retries;
1732 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES);
1733
1734 sinfo->ack_signal = (s8)msta_link->ack_signal;
1735 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL);
1736
1737 sinfo->avg_ack_signal =
1738 -(s8)ewma_avg_signal_read(&msta_link->avg_ack_signal);
1739 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG);
1740
1741 if (mtk_wed_device_active(&dev->mt76.mmio.wed)) {
1742 sinfo->tx_bytes = msta_link->wcid.stats.tx_bytes;
1743 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64);
1744
1745 sinfo->rx_bytes = msta_link->wcid.stats.rx_bytes;
1746 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BYTES64);
1747
1748 sinfo->tx_packets = msta_link->wcid.stats.tx_packets;
1749 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
1750
1751 sinfo->rx_packets = msta_link->wcid.stats.rx_packets;
1752 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS);
1753 }
1754 }
1755
1756 static void mt7996_link_rate_ctrl_update(void *data,
1757 struct mt7996_sta_link *msta_link)
1758 {
1759 struct mt7996_sta *msta = msta_link->sta;
1760 struct mt7996_dev *dev = msta->vif->deflink.phy->dev;
1761 u32 *changed = data;
1762
1763 spin_lock_bh(&dev->mt76.sta_poll_lock);
1764
1765 msta_link->changed |= *changed;
1766 if (list_empty(&msta_link->rc_list))
1767 list_add_tail(&msta_link->rc_list, &dev->sta_rc_list);
1768
1769 spin_unlock_bh(&dev->mt76.sta_poll_lock);
1770 }
1771
1772 static void mt7996_link_sta_rc_update(struct ieee80211_hw *hw,
1773 struct ieee80211_vif *vif,
1774 struct ieee80211_link_sta *link_sta,
1775 u32 changed)
1776 {
1777 struct ieee80211_sta *sta = link_sta->sta;
1778 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
1779 struct mt7996_sta_link *msta_link;
1780
1781 rcu_read_lock();
1782
1783 msta_link = rcu_dereference(msta->link[link_sta->link_id]);
1784 if (msta_link) {
1785 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1786
1787 mt7996_link_rate_ctrl_update(&changed, msta_link);
1788 ieee80211_queue_work(hw, &dev->rc_work);
1789 }
1790
1791 rcu_read_unlock();
1792 }
1793
1794 static void mt7996_sta_rate_ctrl_update(void *data, struct ieee80211_sta *sta)
1795 {
1796 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
1797 struct mt7996_sta_link *msta_link;
1798 u32 *changed = data;
1799
1800 msta_link = rcu_dereference(msta->link[msta->deflink_id]);
1801 if (msta_link)
1802 mt7996_link_rate_ctrl_update(&changed, msta_link);
1803 }
1804
1805 static int
1806 mt7996_set_bitrate_mask(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1807 const struct cfg80211_bitrate_mask *mask)
1808 {
1809 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1810 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
1811 u32 changed = IEEE80211_RC_SUPP_RATES_CHANGED;
1812
1813 mvif->deflink.bitrate_mask = *mask;
1814
1815 /* if multiple rates across different preambles are given we can
1816 * reconfigure this info with all peers using sta_rec command with
1817 * the below exception cases.
1818 * - single rate : if a rate is passed along with different preambles,
1819 * we select the highest one as fixed rate. i.e VHT MCS for VHT peers.
1820 * - multiple rates: if it's not in range format i.e 0-{7,8,9} for VHT
1821 * then multiple MCS setting (MCS 4,5,6) is not supported.
1822 */
1823 ieee80211_iterate_stations_atomic(hw, mt7996_sta_rate_ctrl_update,
1824 &changed);
1825 ieee80211_queue_work(hw, &dev->rc_work);
1826
1827 return 0;
1828 }
1829
1830 static void mt7996_sta_set_4addr(struct ieee80211_hw *hw,
1831 struct ieee80211_vif *vif,
1832 struct ieee80211_sta *sta,
1833 bool enabled)
1834 {
1835 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
1836 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1837 struct ieee80211_link_sta *link_sta;
1838 unsigned int link_id;
1839
1840 mutex_lock(&dev->mt76.mutex);
1841
1842 for_each_sta_active_link(vif, sta, link_sta, link_id) {
1843 struct mt7996_sta_link *msta_link;
1844 struct mt7996_vif_link *link;
1845
1846 link = mt7996_vif_link(dev, vif, link_id);
1847 if (!link)
1848 continue;
1849
1850 msta_link = mt76_dereference(msta->link[link_id], &dev->mt76);
1851 if (!msta_link)
1852 continue;
1853
1854 if (enabled)
1855 set_bit(MT_WCID_FLAG_4ADDR, &msta_link->wcid.flags);
1856 else
1857 clear_bit(MT_WCID_FLAG_4ADDR, &msta_link->wcid.flags);
1858
1859 if (!msta_link->wcid.sta)
1860 continue;
1861
1862 mt7996_mcu_wtbl_update_hdr_trans(dev, vif, link, msta_link);
1863 }
1864
1865 mutex_unlock(&dev->mt76.mutex);
1866 }
1867
1868 static void mt7996_sta_set_decap_offload(struct ieee80211_hw *hw,
1869 struct ieee80211_vif *vif,
1870 struct ieee80211_sta *sta,
1871 bool enabled)
1872 {
1873 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
1874 struct mt7996_dev *dev = mt7996_hw_dev(hw);
1875 struct ieee80211_link_sta *link_sta;
1876 unsigned int link_id;
1877
1878 mutex_lock(&dev->mt76.mutex);
1879
1880 for_each_sta_active_link(vif, sta, link_sta, link_id) {
1881 struct mt7996_sta_link *msta_link;
1882 struct mt7996_vif_link *link;
1883
1884 link = mt7996_vif_link(dev, vif, link_id);
1885 if (!link)
1886 continue;
1887
1888 msta_link = mt76_dereference(msta->link[link_id], &dev->mt76);
1889 if (!msta_link)
1890 continue;
1891
1892 if (enabled)
1893 set_bit(MT_WCID_FLAG_HDR_TRANS,
1894 &msta_link->wcid.flags);
1895 else
1896 clear_bit(MT_WCID_FLAG_HDR_TRANS,
1897 &msta_link->wcid.flags);
1898
1899 if (!msta_link->wcid.sta)
1900 continue;
1901
1902 mt7996_mcu_wtbl_update_hdr_trans(dev, vif, link, msta_link);
1903 }
1904
1905 mutex_unlock(&dev->mt76.mutex);
1906 }
1907
1908 static const char mt7996_gstrings_stats[][ETH_GSTRING_LEN] = {
1909 "tx_ampdu_cnt",
1910 "tx_stop_q_empty_cnt",
1911 "tx_mpdu_attempts",
1912 "tx_mpdu_success",
1913 "tx_rwp_fail_cnt",
1914 "tx_rwp_need_cnt",
1915 "tx_pkt_ebf_cnt",
1916 "tx_pkt_ibf_cnt",
1917 "tx_ampdu_len:0-1",
1918 "tx_ampdu_len:2-10",
1919 "tx_ampdu_len:11-19",
1920 "tx_ampdu_len:20-28",
1921 "tx_ampdu_len:29-37",
1922 "tx_ampdu_len:38-46",
1923 "tx_ampdu_len:47-55",
1924 "tx_ampdu_len:56-79",
1925 "tx_ampdu_len:80-103",
1926 "tx_ampdu_len:104-127",
1927 "tx_ampdu_len:128-151",
1928 "tx_ampdu_len:152-175",
1929 "tx_ampdu_len:176-199",
1930 "tx_ampdu_len:200-223",
1931 "tx_ampdu_len:224-247",
1932 "ba_miss_count",
1933 "tx_beamformer_ppdu_iBF",
1934 "tx_beamformer_ppdu_eBF",
1935 "tx_beamformer_rx_feedback_all",
1936 "tx_beamformer_rx_feedback_he",
1937 "tx_beamformer_rx_feedback_vht",
1938 "tx_beamformer_rx_feedback_ht",
1939 "tx_beamformer_rx_feedback_bw", /* zero based idx: 20, 40, 80, 160 */
1940 "tx_beamformer_rx_feedback_nc",
1941 "tx_beamformer_rx_feedback_nr",
1942 "tx_beamformee_ok_feedback_pkts",
1943 "tx_beamformee_feedback_trig",
1944 "tx_mu_beamforming",
1945 "tx_mu_mpdu",
1946 "tx_mu_successful_mpdu",
1947 "tx_su_successful_mpdu",
1948 "tx_msdu_pack_1",
1949 "tx_msdu_pack_2",
1950 "tx_msdu_pack_3",
1951 "tx_msdu_pack_4",
1952 "tx_msdu_pack_5",
1953 "tx_msdu_pack_6",
1954 "tx_msdu_pack_7",
1955 "tx_msdu_pack_8",
1956
1957 /* rx counters */
1958 "rx_fifo_full_cnt",
1959 "rx_mpdu_cnt",
1960 "channel_idle_cnt",
1961 "rx_vector_mismatch_cnt",
1962 "rx_delimiter_fail_cnt",
1963 "rx_len_mismatch_cnt",
1964 "rx_ampdu_cnt",
1965 "rx_ampdu_bytes_cnt",
1966 "rx_ampdu_valid_subframe_cnt",
1967 "rx_ampdu_valid_subframe_b_cnt",
1968 "rx_pfdrop_cnt",
1969 "rx_vec_queue_overflow_drop_cnt",
1970 "rx_ba_cnt",
1971
1972 /* per vif counters */
1973 "v_tx_mode_cck",
1974 "v_tx_mode_ofdm",
1975 "v_tx_mode_ht",
1976 "v_tx_mode_ht_gf",
1977 "v_tx_mode_vht",
1978 "v_tx_mode_he_su",
1979 "v_tx_mode_he_ext_su",
1980 "v_tx_mode_he_tb",
1981 "v_tx_mode_he_mu",
1982 "v_tx_mode_eht_su",
1983 "v_tx_mode_eht_trig",
1984 "v_tx_mode_eht_mu",
1985 "v_tx_bw_20",
1986 "v_tx_bw_40",
1987 "v_tx_bw_80",
1988 "v_tx_bw_160",
1989 "v_tx_bw_320",
1990 "v_tx_mcs_0",
1991 "v_tx_mcs_1",
1992 "v_tx_mcs_2",
1993 "v_tx_mcs_3",
1994 "v_tx_mcs_4",
1995 "v_tx_mcs_5",
1996 "v_tx_mcs_6",
1997 "v_tx_mcs_7",
1998 "v_tx_mcs_8",
1999 "v_tx_mcs_9",
2000 "v_tx_mcs_10",
2001 "v_tx_mcs_11",
2002 "v_tx_mcs_12",
2003 "v_tx_mcs_13",
2004 "v_tx_nss_1",
2005 "v_tx_nss_2",
2006 "v_tx_nss_3",
2007 "v_tx_nss_4",
2008 };
2009
2010 #define MT7996_SSTATS_LEN ARRAY_SIZE(mt7996_gstrings_stats)
2011
2012 /* Ethtool related API */
2013 static
2014 void mt7996_get_et_strings(struct ieee80211_hw *hw,
2015 struct ieee80211_vif *vif,
2016 u32 sset, u8 *data)
2017 {
2018 if (sset == ETH_SS_STATS)
2019 memcpy(data, mt7996_gstrings_stats,
2020 sizeof(mt7996_gstrings_stats));
2021 }
2022
2023 static
2024 int mt7996_get_et_sset_count(struct ieee80211_hw *hw,
2025 struct ieee80211_vif *vif, int sset)
2026 {
2027 if (sset == ETH_SS_STATS)
2028 return MT7996_SSTATS_LEN;
2029
2030 return 0;
2031 }
2032
2033 static void mt7996_ethtool_worker(void *wi_data, struct ieee80211_sta *sta)
2034 {
2035 struct mt76_ethtool_worker_info *wi = wi_data;
2036 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
2037 struct mt7996_sta_link *msta_link = &msta->deflink;
2038
2039 if (msta->vif->deflink.mt76.idx != wi->idx)
2040 return;
2041
2042 mt76_ethtool_worker(wi, &msta_link->wcid.stats, true);
2043 }
2044
2045 static
2046 void mt7996_get_et_stats(struct ieee80211_hw *hw,
2047 struct ieee80211_vif *vif,
2048 struct ethtool_stats *stats, u64 *data)
2049 {
2050 struct mt7996_dev *dev = mt7996_hw_dev(hw);
2051 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
2052 struct mt7996_phy *phy = mt7996_vif_link_phy(&mvif->deflink);
2053 struct mt76_mib_stats *mib = &phy->mib;
2054 struct mt76_ethtool_worker_info wi = {
2055 .data = data,
2056 .idx = mvif->deflink.mt76.idx,
2057 };
2058 /* See mt7996_ampdu_stat_read_phy, etc */
2059 int i, ei = 0;
2060
2061 if (!phy)
2062 return;
2063
2064 mutex_lock(&dev->mt76.mutex);
2065
2066 mt7996_mac_update_stats(phy);
2067
2068 data[ei++] = mib->tx_ampdu_cnt;
2069 data[ei++] = mib->tx_stop_q_empty_cnt;
2070 data[ei++] = mib->tx_mpdu_attempts_cnt;
2071 data[ei++] = mib->tx_mpdu_success_cnt;
2072 data[ei++] = mib->tx_rwp_fail_cnt;
2073 data[ei++] = mib->tx_rwp_need_cnt;
2074 data[ei++] = mib->tx_bf_ebf_ppdu_cnt;
2075 data[ei++] = mib->tx_bf_ibf_ppdu_cnt;
2076
2077 /* Tx ampdu stat */
2078 for (i = 0; i < 15 /*ARRAY_SIZE(bound)*/; i++)
2079 data[ei++] = phy->mt76->aggr_stats[i];
2080 data[ei++] = phy->mib.ba_miss_cnt;
2081
2082 /* Tx Beamformer monitor */
2083 data[ei++] = mib->tx_bf_ibf_ppdu_cnt;
2084 data[ei++] = mib->tx_bf_ebf_ppdu_cnt;
2085
2086 /* Tx Beamformer Rx feedback monitor */
2087 data[ei++] = mib->tx_bf_rx_fb_all_cnt;
2088 data[ei++] = mib->tx_bf_rx_fb_he_cnt;
2089 data[ei++] = mib->tx_bf_rx_fb_vht_cnt;
2090 data[ei++] = mib->tx_bf_rx_fb_ht_cnt;
2091
2092 data[ei++] = mib->tx_bf_rx_fb_bw;
2093 data[ei++] = mib->tx_bf_rx_fb_nc_cnt;
2094 data[ei++] = mib->tx_bf_rx_fb_nr_cnt;
2095
2096 /* Tx Beamformee Rx NDPA & Tx feedback report */
2097 data[ei++] = mib->tx_bf_fb_cpl_cnt;
2098 data[ei++] = mib->tx_bf_fb_trig_cnt;
2099
2100 /* Tx SU & MU counters */
2101 data[ei++] = mib->tx_mu_bf_cnt;
2102 data[ei++] = mib->tx_mu_mpdu_cnt;
2103 data[ei++] = mib->tx_mu_acked_mpdu_cnt;
2104 data[ei++] = mib->tx_su_acked_mpdu_cnt;
2105
2106 /* Tx amsdu info (pack-count histogram) */
2107 for (i = 0; i < ARRAY_SIZE(mib->tx_amsdu); i++)
2108 data[ei++] = mib->tx_amsdu[i];
2109
2110 /* rx counters */
2111 data[ei++] = mib->rx_fifo_full_cnt;
2112 data[ei++] = mib->rx_mpdu_cnt;
2113 data[ei++] = mib->channel_idle_cnt;
2114 data[ei++] = mib->rx_vector_mismatch_cnt;
2115 data[ei++] = mib->rx_delimiter_fail_cnt;
2116 data[ei++] = mib->rx_len_mismatch_cnt;
2117 data[ei++] = mib->rx_ampdu_cnt;
2118 data[ei++] = mib->rx_ampdu_bytes_cnt;
2119 data[ei++] = mib->rx_ampdu_valid_subframe_cnt;
2120 data[ei++] = mib->rx_ampdu_valid_subframe_bytes_cnt;
2121 data[ei++] = mib->rx_pfdrop_cnt;
2122 data[ei++] = mib->rx_vec_queue_overflow_drop_cnt;
2123 data[ei++] = mib->rx_ba_cnt;
2124
2125 /* Add values for all stations owned by this vif */
2126 wi.initial_stat_idx = ei;
2127 ieee80211_iterate_stations_atomic(hw, mt7996_ethtool_worker, &wi);
2128
2129 mutex_unlock(&dev->mt76.mutex);
2130
2131 if (wi.sta_count == 0)
2132 return;
2133
2134 ei += wi.worker_stat_count;
2135 if (ei != MT7996_SSTATS_LEN)
2136 dev_err(dev->mt76.dev, "ei: %d MT7996_SSTATS_LEN: %d",
2137 ei, (int)MT7996_SSTATS_LEN);
2138 }
2139
2140 static void
2141 mt7996_twt_teardown_request(struct ieee80211_hw *hw,
2142 struct ieee80211_sta *sta,
2143 u8 flowid)
2144 {
2145 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
2146 struct mt7996_sta_link *msta_link = &msta->deflink;
2147 struct mt7996_vif_link *link = &msta->vif->deflink;
2148 struct mt7996_dev *dev = mt7996_hw_dev(hw);
2149
2150 mutex_lock(&dev->mt76.mutex);
2151 mt7996_mac_twt_teardown_flow(dev, link, msta_link, flowid);
2152 mutex_unlock(&dev->mt76.mutex);
2153 }
2154
2155 static int
2156 mt7996_set_radar_background(struct ieee80211_hw *hw,
2157 struct cfg80211_chan_def *chandef)
2158 {
2159 struct mt7996_dev *dev = mt7996_hw_dev(hw);
2160 struct mt7996_phy *phy;
2161 int ret = -EINVAL;
2162 bool running;
2163
2164 if (chandef)
2165 phy = mt7996_band_phy(dev, chandef->chan->band);
2166 else
2167 phy = dev->rdd2_phy;
2168 if (!phy)
2169 return -EINVAL;
2170
2171 mutex_lock(&dev->mt76.mutex);
2172
2173 if (dev->mt76.region == NL80211_DFS_UNSET)
2174 goto out;
2175
2176 if (dev->rdd2_phy && dev->rdd2_phy != phy) {
2177 /* rdd2 is already locked */
2178 ret = -EBUSY;
2179 goto out;
2180 }
2181
2182 /* rdd2 already configured on a radar channel */
2183 running = dev->rdd2_phy &&
2184 cfg80211_chandef_valid(&dev->rdd2_chandef) &&
2185 !!(dev->rdd2_chandef.chan->flags & IEEE80211_CHAN_RADAR);
2186
2187 if (!chandef || running ||
2188 !(chandef->chan->flags & IEEE80211_CHAN_RADAR)) {
2189 ret = mt7996_mcu_rdd_background_enable(phy, NULL);
2190 if (ret)
2191 goto out;
2192
2193 if (!running)
2194 goto update_phy;
2195 }
2196
2197 ret = mt7996_mcu_rdd_background_enable(phy, chandef);
2198 if (ret)
2199 goto out;
2200
2201 update_phy:
2202 dev->rdd2_phy = chandef ? phy : NULL;
2203 if (chandef)
2204 dev->rdd2_chandef = *chandef;
2205 out:
2206 mutex_unlock(&dev->mt76.mutex);
2207
2208 return ret;
2209 }
2210
2211 static int
2212 mt7996_net_fill_forward_path(struct ieee80211_hw *hw,
2213 struct ieee80211_vif *vif,
2214 struct ieee80211_sta *sta,
2215 struct net_device_path_ctx *ctx,
2216 struct net_device_path *path)
2217 {
2218 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
2219 struct mt7996_dev *dev = mt7996_hw_dev(hw);
2220 struct mtk_wed_device *wed = &dev->mt76.mmio.wed;
2221 struct mt7996_sta_link *msta_link;
2222 struct mt7996_vif_link *link;
2223
2224 link = mt7996_vif_link(dev, vif, msta->deflink_id);
2225 if (!link)
2226 return -EIO;
2227
2228 msta_link = rcu_dereference(msta->link[msta->deflink_id]);
2229 if (!msta_link)
2230 return -EIO;
2231
2232 if (!msta_link->wcid.sta || msta_link->wcid.idx > MT7996_WTBL_STA)
2233 return -EIO;
2234
2235 if (dev->hif2 &&
2236 ((is_mt7996(&dev->mt76) && msta_link->wcid.phy_idx == MT_BAND2) ||
2237 (is_mt7992(&dev->mt76) && msta_link->wcid.phy_idx == MT_BAND1)))
2238 wed = &dev->mt76.mmio.wed_hif2;
2239
2240 if (!mtk_wed_device_active(wed) &&
2241 !mt76_npu_device_active(&dev->mt76))
2242 return -ENODEV;
2243
2244 path->type = DEV_PATH_MTK_WDMA;
2245 path->dev = ctx->dev;
2246 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
2247 if (mtk_wed_device_active(wed))
2248 path->mtk_wdma.wdma_idx = wed->wdma_idx;
2249 else
2250 #endif
2251 path->mtk_wdma.wdma_idx = link->mt76.band_idx;
2252 path->mtk_wdma.bss = link->mt76.idx;
2253 path->mtk_wdma.queue = 0;
2254 path->mtk_wdma.wcid = msta_link->wcid.idx;
2255
2256 if (ieee80211_hw_check(hw, SUPPORTS_AMSDU_IN_AMPDU) &&
2257 mtk_wed_is_amsdu_supported(wed))
2258 path->mtk_wdma.amsdu = msta_link->wcid.amsdu;
2259 else
2260 path->mtk_wdma.amsdu = 0;
2261 ctx->dev = NULL;
2262
2263 return 0;
2264 }
2265
2266 static int
2267 mt7996_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2268 u16 old_links, u16 new_links,
2269 struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS])
2270 {
2271 struct mt7996_dev *dev = mt7996_hw_dev(hw);
2272 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
2273 int ret = 0;
2274
2275 mutex_lock(&dev->mt76.mutex);
2276
2277 if (!old_links) {
2278 int idx;
2279
2280 idx = get_own_mld_idx(dev->mld_idx_mask, true);
2281 if (idx < 0) {
2282 ret = -ENOSPC;
2283 goto out;
2284 }
2285 mvif->mld_group_idx = idx;
2286 dev->mld_idx_mask |= BIT_ULL(mvif->mld_group_idx);
2287
2288 idx = get_free_idx(dev->mld_remap_idx_mask, 0, 15) - 1;
2289 if (idx < 0) {
2290 ret = -ENOSPC;
2291 goto out;
2292 }
2293 mvif->mld_remap_idx = idx;
2294 dev->mld_remap_idx_mask |= BIT_ULL(mvif->mld_remap_idx);
2295 }
2296
2297 if (new_links)
2298 goto out;
2299
2300 dev->mld_idx_mask &= ~BIT_ULL(mvif->mld_group_idx);
2301 dev->mld_remap_idx_mask &= ~BIT_ULL(mvif->mld_remap_idx);
2302
2303 out:
2304 mutex_unlock(&dev->mt76.mutex);
2305
2306 return ret;
2307 }
2308
2309 static void
2310 mt7996_reconfig_complete(struct ieee80211_hw *hw,
2311 enum ieee80211_reconfig_type reconfig_type)
2312 {
2313 struct mt7996_dev *dev = mt7996_hw_dev(hw);
2314 struct mt7996_phy *phy;
2315
2316 ieee80211_wake_queues(hw);
2317 mt7996_for_each_phy(dev, phy)
2318 ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
2319 MT7996_WATCHDOG_TIME);
2320 }
2321
2322 const struct ieee80211_ops mt7996_ops = {
2323 .add_chanctx = mt76_add_chanctx,
2324 .remove_chanctx = mt76_remove_chanctx,
2325 .change_chanctx = mt76_change_chanctx,
2326 .assign_vif_chanctx = mt76_assign_vif_chanctx,
2327 .unassign_vif_chanctx = mt76_unassign_vif_chanctx,
2328 .switch_vif_chanctx = mt76_switch_vif_chanctx,
2329 .tx = mt7996_tx,
2330 .start = mt7996_start,
2331 .stop = mt7996_stop,
2332 .add_interface = mt7996_add_interface,
2333 .remove_interface = mt7996_remove_interface,
2334 .config = mt7996_config,
2335 .conf_tx = mt7996_conf_tx,
2336 .configure_filter = mt7996_configure_filter,
2337 .vif_cfg_changed = mt7996_vif_cfg_changed,
2338 .link_info_changed = mt7996_link_info_changed,
2339 .sta_state = mt7996_sta_state,
2340 .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
2341 .link_sta_rc_update = mt7996_link_sta_rc_update,
2342 .set_key = mt7996_set_key,
2343 .ampdu_action = mt7996_ampdu_action,
2344 .set_rts_threshold = mt7996_set_rts_threshold,
2345 .wake_tx_queue = mt76_wake_tx_queue,
2346 .hw_scan = mt76_hw_scan,
2347 .cancel_hw_scan = mt76_cancel_hw_scan,
2348 .remain_on_channel = mt76_remain_on_channel,
2349 .cancel_remain_on_channel = mt76_cancel_remain_on_channel,
2350 .release_buffered_frames = mt76_release_buffered_frames,
2351 .get_txpower = mt7996_get_txpower,
2352 .channel_switch_beacon = mt7996_channel_switch_beacon,
2353 .post_channel_switch = mt7996_post_channel_switch,
2354 .get_stats = mt7996_get_stats,
2355 .get_et_sset_count = mt7996_get_et_sset_count,
2356 .get_et_stats = mt7996_get_et_stats,
2357 .get_et_strings = mt7996_get_et_strings,
2358 .get_tsf = mt7996_get_tsf,
2359 .set_tsf = mt7996_set_tsf,
2360 .offset_tsf = mt7996_offset_tsf,
2361 .get_survey = mt76_get_survey,
2362 .get_antenna = mt76_get_antenna,
2363 .set_antenna = mt7996_set_antenna,
2364 .set_bitrate_mask = mt7996_set_bitrate_mask,
2365 .set_coverage_class = mt7996_set_coverage_class,
2366 .sta_statistics = mt7996_sta_statistics,
2367 .sta_set_4addr = mt7996_sta_set_4addr,
2368 .sta_set_decap_offload = mt7996_sta_set_decap_offload,
2369 .add_twt_setup = mt7996_mac_add_twt_setup,
2370 .twt_teardown_request = mt7996_twt_teardown_request,
2371 #ifdef CONFIG_MAC80211_DEBUGFS
2372 .sta_add_debugfs = mt7996_sta_add_debugfs,
2373 .link_sta_add_debugfs = mt7996_link_sta_add_debugfs,
2374 #endif
2375 .set_radar_background = mt7996_set_radar_background,
2376 .net_fill_forward_path = mt7996_net_fill_forward_path,
2377 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
2378 .net_setup_tc = mt76_wed_net_setup_tc,
2379 #elif defined(CONFIG_MT7996_NPU)
2380 .net_setup_tc = mt76_npu_net_setup_tc,
2381 #endif
2382 .change_vif_links = mt7996_change_vif_links,
2383 .change_sta_links = mt7996_mac_sta_change_links,
2384 .reconfig_complete = mt7996_reconfig_complete,
2385 };