File Index
Files and directories
Sign in
FILE

main.c

File preview with syntax highlighting.

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