File Index
Files and directories
Sign in
FILE

main.c

File preview with syntax highlighting.

linux-6.19.14/drivers/net/wireless/mediatek/mt76/mt7925/main.c C
   1// SPDX-License-Identifier: BSD-3-Clause-Clear
   2/* Copyright (C) 2023 MediaTek Inc. */
   3
   4#include <linux/etherdevice.h>
   5#include <linux/platform_device.h>
   6#include <linux/pci.h>
   7#include <linux/module.h>
   8#include <linux/ctype.h>
   9#include <net/ipv6.h>
  10#include "mt7925.h"
  11#include "regd.h"
  12#include "mcu.h"
  13#include "mac.h"
  14
  15static void
  16mt7925_init_he_caps(struct mt792x_phy *phy, enum nl80211_band band,
  17		    struct ieee80211_sband_iftype_data *data,
  18		    enum nl80211_iftype iftype)
  19{
  20	struct ieee80211_sta_he_cap *he_cap = &data->he_cap;
  21	struct ieee80211_he_cap_elem *he_cap_elem = &he_cap->he_cap_elem;
  22	struct ieee80211_he_mcs_nss_supp *he_mcs = &he_cap->he_mcs_nss_supp;
  23	int i, nss = hweight8(phy->mt76->antenna_mask);
  24	u16 mcs_map = 0;
  25
  26	for (i = 0; i < 8; i++) {
  27		if (i < nss)
  28			mcs_map |= (IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2));
  29		else
  30			mcs_map |= (IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
  31	}
  32
  33	he_cap->has_he = true;
  34
  35	he_cap_elem->mac_cap_info[0] = IEEE80211_HE_MAC_CAP0_HTC_HE;
  36	he_cap_elem->mac_cap_info[3] = IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
  37				       IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3;
  38	he_cap_elem->mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU;
  39
  40	if (band == NL80211_BAND_2GHZ)
  41		he_cap_elem->phy_cap_info[0] =
  42			IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
  43	else
  44		he_cap_elem->phy_cap_info[0] =
  45			IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
  46			IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
  47
  48	he_cap_elem->phy_cap_info[1] =
  49		IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD;
  50	he_cap_elem->phy_cap_info[2] =
  51		IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
  52		IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
  53		IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
  54		IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
  55		IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO;
  56
  57	switch (iftype) {
  58	case NL80211_IFTYPE_AP:
  59		he_cap_elem->mac_cap_info[2] |=
  60			IEEE80211_HE_MAC_CAP2_BSR;
  61		he_cap_elem->mac_cap_info[4] |=
  62			IEEE80211_HE_MAC_CAP4_BQR;
  63		he_cap_elem->mac_cap_info[5] |=
  64			IEEE80211_HE_MAC_CAP5_OM_CTRL_UL_MU_DATA_DIS_RX;
  65		he_cap_elem->phy_cap_info[3] |=
  66			IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK |
  67			IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK;
  68		he_cap_elem->phy_cap_info[6] |=
  69			IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE |
  70			IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT;
  71		he_cap_elem->phy_cap_info[9] |=
  72			IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
  73			IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU;
  74		break;
  75	case NL80211_IFTYPE_STATION:
  76		he_cap_elem->mac_cap_info[1] |=
  77			IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US;
  78
  79		if (band == NL80211_BAND_2GHZ)
  80			he_cap_elem->phy_cap_info[0] |=
  81				IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G;
  82		else
  83			he_cap_elem->phy_cap_info[0] |=
  84				IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G;
  85
  86		he_cap_elem->phy_cap_info[1] |=
  87			IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
  88			IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US;
  89		he_cap_elem->phy_cap_info[3] |=
  90			IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK |
  91			IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK;
  92		he_cap_elem->phy_cap_info[4] |=
  93			IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE |
  94			IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4 |
  95			IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_4;
  96		he_cap_elem->phy_cap_info[5] |=
  97			IEEE80211_HE_PHY_CAP5_NG16_SU_FEEDBACK |
  98			IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK;
  99		he_cap_elem->phy_cap_info[6] |=
 100			IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_42_SU |
 101			IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU |
 102			IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB |
 103			IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE |
 104			IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT;
 105		he_cap_elem->phy_cap_info[7] |=
 106			IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP |
 107			IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI;
 108		he_cap_elem->phy_cap_info[8] |=
 109			IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
 110			IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU |
 111			IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU |
 112			IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_484;
 113		he_cap_elem->phy_cap_info[9] |=
 114			IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM |
 115			IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK |
 116			IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
 117			IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU |
 118			IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB |
 119			IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB;
 120		break;
 121	default:
 122		break;
 123	}
 124
 125	he_mcs->rx_mcs_80 = cpu_to_le16(mcs_map);
 126	he_mcs->tx_mcs_80 = cpu_to_le16(mcs_map);
 127	he_mcs->rx_mcs_160 = cpu_to_le16(mcs_map);
 128	he_mcs->tx_mcs_160 = cpu_to_le16(mcs_map);
 129
 130	memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres));
 131
 132	if (he_cap_elem->phy_cap_info[6] &
 133	    IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
 134		mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss, band);
 135	} else {
 136		he_cap_elem->phy_cap_info[9] |=
 137			u8_encode_bits(IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US,
 138				       IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK);
 139	}
 140
 141	if (band == NL80211_BAND_6GHZ) {
 142		struct ieee80211_supported_band *sband =
 143			&phy->mt76->sband_5g.sband;
 144		struct ieee80211_sta_ht_cap *ht_cap = &sband->ht_cap;
 145
 146		u16 cap = IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS |
 147			  IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS;
 148
 149		cap |= u16_encode_bits(ht_cap->ampdu_density,
 150				       IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START) |
 151		       u16_encode_bits(IEEE80211_VHT_MAX_AMPDU_1024K,
 152				       IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP) |
 153		       u16_encode_bits(IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454,
 154				       IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN);
 155
 156		data->he_6ghz_capa.capa = cpu_to_le16(cap);
 157	}
 158}
 159
 160static void
 161mt7925_init_eht_caps(struct mt792x_phy *phy, enum nl80211_band band,
 162		     struct ieee80211_sband_iftype_data *data)
 163{
 164	struct ieee80211_sta_eht_cap *eht_cap = &data->eht_cap;
 165	struct ieee80211_eht_cap_elem_fixed *eht_cap_elem = &eht_cap->eht_cap_elem;
 166	struct ieee80211_eht_mcs_nss_supp *eht_nss = &eht_cap->eht_mcs_nss_supp;
 167	enum nl80211_chan_width width = phy->mt76->chandef.width;
 168	int nss = hweight8(phy->mt76->antenna_mask);
 169	int sts = hweight16(phy->mt76->chainmask);
 170	u8 val;
 171
 172	if (!phy->dev->has_eht)
 173		return;
 174
 175	eht_cap->has_eht = true;
 176
 177	eht_cap_elem->mac_cap_info[0] =
 178		IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
 179		IEEE80211_EHT_MAC_CAP0_OM_CONTROL;
 180
 181	eht_cap_elem->phy_cap_info[0] =
 182		IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
 183		IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
 184		IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE;
 185
 186	eht_cap_elem->phy_cap_info[0] |=
 187		u8_encode_bits(u8_get_bits(sts - 1, BIT(0)),
 188			       IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK);
 189
 190	eht_cap_elem->phy_cap_info[1] =
 191		u8_encode_bits(u8_get_bits(sts - 1, GENMASK(2, 1)),
 192			       IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK) |
 193		u8_encode_bits(sts - 1,
 194			       IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK);
 195
 196	eht_cap_elem->phy_cap_info[2] =
 197		u8_encode_bits(sts - 1, IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK) |
 198		u8_encode_bits(sts - 1, IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK);
 199
 200	eht_cap_elem->phy_cap_info[3] =
 201		IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
 202		IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
 203		IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
 204		IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
 205		IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
 206		IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
 207		IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK;
 208
 209	eht_cap_elem->phy_cap_info[4] =
 210		u8_encode_bits(min_t(int, sts - 1, 2),
 211			       IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK);
 212
 213	eht_cap_elem->phy_cap_info[5] =
 214		IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
 215		u8_encode_bits(IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US,
 216			       IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK) |
 217		u8_encode_bits(u8_get_bits(0x11, GENMASK(1, 0)),
 218			       IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK);
 219
 220	val = width == NL80211_CHAN_WIDTH_160 ? 0x7 :
 221	      width == NL80211_CHAN_WIDTH_80 ? 0x3 : 0x1;
 222	eht_cap_elem->phy_cap_info[6] =
 223		u8_encode_bits(u8_get_bits(0x11, GENMASK(4, 2)),
 224			       IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK) |
 225		u8_encode_bits(val, IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK);
 226
 227	eht_cap_elem->phy_cap_info[7] =
 228		IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
 229		IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
 230		IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
 231		IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ;
 232
 233	val = u8_encode_bits(nss, IEEE80211_EHT_MCS_NSS_RX) |
 234	      u8_encode_bits(nss, IEEE80211_EHT_MCS_NSS_TX);
 235
 236	eht_nss->bw._80.rx_tx_mcs9_max_nss = val;
 237	eht_nss->bw._80.rx_tx_mcs11_max_nss = val;
 238	eht_nss->bw._80.rx_tx_mcs13_max_nss = val;
 239	eht_nss->bw._160.rx_tx_mcs9_max_nss = val;
 240	eht_nss->bw._160.rx_tx_mcs11_max_nss = val;
 241	eht_nss->bw._160.rx_tx_mcs13_max_nss = val;
 242}
 243
 244int mt7925_init_mlo_caps(struct mt792x_phy *phy)
 245{
 246	struct wiphy *wiphy = phy->mt76->hw->wiphy;
 247	static const u8 ext_capa_sta[] = {
 248		[2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
 249		[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
 250	};
 251	static struct wiphy_iftype_ext_capab ext_capab[] = {
 252		{
 253			.iftype = NL80211_IFTYPE_STATION,
 254			.extended_capabilities = ext_capa_sta,
 255			.extended_capabilities_mask = ext_capa_sta,
 256			.extended_capabilities_len = sizeof(ext_capa_sta),
 257		},
 258	};
 259
 260	if (!(phy->chip_cap & MT792x_CHIP_CAP_MLO_EN))
 261		return 0;
 262
 263	ext_capab[0].eml_capabilities = phy->eml_cap;
 264	ext_capab[0].mld_capa_and_ops =
 265		u16_encode_bits(0, IEEE80211_MLD_CAP_OP_MAX_SIMUL_LINKS);
 266
 267	wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO;
 268	wiphy->iftype_ext_capab = ext_capab;
 269	wiphy->num_iftype_ext_capab = ARRAY_SIZE(ext_capab);
 270
 271	return 0;
 272}
 273
 274static void
 275__mt7925_set_stream_he_eht_caps(struct mt792x_phy *phy,
 276				struct ieee80211_supported_band *sband,
 277				enum nl80211_band band)
 278{
 279	struct ieee80211_sband_iftype_data *data = phy->iftype[band];
 280	int i, n = 0;
 281
 282	for (i = 0; i < NUM_NL80211_IFTYPES; i++) {
 283		switch (i) {
 284		case NL80211_IFTYPE_STATION:
 285		case NL80211_IFTYPE_AP:
 286			break;
 287		default:
 288			continue;
 289		}
 290
 291		data[n].types_mask = BIT(i);
 292		mt7925_init_he_caps(phy, band, &data[n], i);
 293		mt7925_init_eht_caps(phy, band, &data[n]);
 294
 295		n++;
 296	}
 297
 298	_ieee80211_set_sband_iftype_data(sband, data, n);
 299}
 300
 301void mt7925_set_stream_he_eht_caps(struct mt792x_phy *phy)
 302{
 303	if (phy->mt76->cap.has_2ghz)
 304		__mt7925_set_stream_he_eht_caps(phy, &phy->mt76->sband_2g.sband,
 305						NL80211_BAND_2GHZ);
 306
 307	if (phy->mt76->cap.has_5ghz)
 308		__mt7925_set_stream_he_eht_caps(phy, &phy->mt76->sband_5g.sband,
 309						NL80211_BAND_5GHZ);
 310
 311	if (phy->mt76->cap.has_6ghz)
 312		__mt7925_set_stream_he_eht_caps(phy, &phy->mt76->sband_6g.sband,
 313						NL80211_BAND_6GHZ);
 314}
 315
 316int __mt7925_start(struct mt792x_phy *phy)
 317{
 318	struct mt76_phy *mphy = phy->mt76;
 319	int err;
 320
 321	err = mt7925_mcu_set_channel_domain(mphy);
 322	if (err)
 323		return err;
 324
 325	err = mt7925_mcu_set_rts_thresh(phy, 0x92b);
 326	if (err)
 327		return err;
 328
 329	mt792x_mac_reset_counters(phy);
 330	set_bit(MT76_STATE_RUNNING, &mphy->state);
 331
 332	ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
 333				     MT792x_WATCHDOG_TIME);
 334
 335	if (phy->chip_cap & MT792x_CHIP_CAP_WF_RF_PIN_CTRL_EVT_EN)
 336		wiphy_rfkill_start_polling(mphy->hw->wiphy);
 337
 338	return 0;
 339}
 340EXPORT_SYMBOL_GPL(__mt7925_start);
 341
 342static int mt7925_start(struct ieee80211_hw *hw)
 343{
 344	struct mt792x_phy *phy = mt792x_hw_phy(hw);
 345	int err;
 346
 347	mt792x_mutex_acquire(phy->dev);
 348	err = __mt7925_start(phy);
 349	mt792x_mutex_release(phy->dev);
 350
 351	return err;
 352}
 353
 354static int mt7925_mac_link_bss_add(struct mt792x_dev *dev,
 355				   struct ieee80211_bss_conf *link_conf,
 356				   struct mt792x_link_sta *mlink)
 357{
 358	struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf);
 359	struct ieee80211_vif *vif = link_conf->vif;
 360	struct mt792x_vif *mvif = mconf->vif;
 361	struct mt76_txq *mtxq;
 362	int idx, ret = 0;
 363
 364	if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
 365		mconf->mt76.idx = MT792x_MAX_INTERFACES;
 366	} else {
 367		mconf->mt76.idx = __ffs64(~dev->mt76.vif_mask);
 368
 369		if (mconf->mt76.idx >= MT792x_MAX_INTERFACES) {
 370			ret = -ENOSPC;
 371			goto out;
 372		}
 373	}
 374
 375	mconf->mt76.omac_idx = ieee80211_vif_is_mld(vif) ?
 376			       0 : mconf->mt76.idx;
 377	mconf->mt76.band_idx = 0xff;
 378	mconf->mt76.wmm_idx = ieee80211_vif_is_mld(vif) ?
 379			      0 : mconf->mt76.idx % MT76_CONNAC_MAX_WMM_SETS;
 380	mconf->mt76.link_idx = hweight16(mvif->valid_links);
 381
 382	if (mvif->phy->mt76->chandef.chan->band != NL80211_BAND_2GHZ)
 383		mconf->mt76.basic_rates_idx = MT792x_BASIC_RATES_TBL + 4;
 384	else
 385		mconf->mt76.basic_rates_idx = MT792x_BASIC_RATES_TBL;
 386
 387	dev->mt76.vif_mask |= BIT_ULL(mconf->mt76.idx);
 388	mvif->phy->omac_mask |= BIT_ULL(mconf->mt76.omac_idx);
 389
 390	idx = MT792x_WTBL_RESERVED - mconf->mt76.idx;
 391
 392	mlink->wcid.idx = idx;
 393	mlink->wcid.tx_info |= MT_WCID_TX_INFO_SET;
 394	mt76_wcid_init(&mlink->wcid, 0);
 395
 396	mt7925_mac_wtbl_update(dev, idx,
 397			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
 398
 399	ewma_rssi_init(&mconf->rssi);
 400
 401	rcu_assign_pointer(dev->mt76.wcid[idx], &mlink->wcid);
 402
 403	ret = mt76_connac_mcu_uni_add_dev(&dev->mphy, link_conf, &mconf->mt76,
 404					  &mlink->wcid, true);
 405	if (ret)
 406		goto out;
 407
 408	if (vif->txq) {
 409		mtxq = (struct mt76_txq *)vif->txq->drv_priv;
 410		mtxq->wcid = idx;
 411	}
 412
 413out:
 414	return ret;
 415}
 416
 417static int
 418mt7925_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
 419{
 420	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
 421	struct mt792x_dev *dev = mt792x_hw_dev(hw);
 422	struct mt792x_phy *phy = mt792x_hw_phy(hw);
 423	int ret = 0;
 424
 425	mt792x_mutex_acquire(dev);
 426
 427	mvif->phy = phy;
 428	mvif->bss_conf.vif = mvif;
 429	mvif->sta.vif = mvif;
 430	mvif->deflink_id = IEEE80211_LINK_UNSPECIFIED;
 431	mvif->mlo_pm_state = MT792x_MLO_LINK_DISASSOC;
 432
 433	ret = mt7925_mac_link_bss_add(dev, &vif->bss_conf, &mvif->sta.deflink);
 434	if (ret < 0)
 435		goto out;
 436
 437	vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
 438	if (phy->chip_cap & MT792x_CHIP_CAP_RSSI_NOTIFY_EVT_EN)
 439		vif->driver_flags |= IEEE80211_VIF_SUPPORTS_CQM_RSSI;
 440
 441out:
 442	mt792x_mutex_release(dev);
 443
 444	return ret;
 445}
 446
 447static void mt7925_roc_iter(void *priv, u8 *mac,
 448			    struct ieee80211_vif *vif)
 449{
 450	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
 451	struct mt792x_phy *phy = priv;
 452
 453	mt7925_mcu_abort_roc(phy, &mvif->bss_conf, phy->roc_token_id);
 454}
 455
 456void mt7925_roc_abort_sync(struct mt792x_dev *dev)
 457{
 458	struct mt792x_phy *phy = &dev->phy;
 459
 460	timer_delete_sync(&phy->roc_timer);
 461	cancel_work_sync(&phy->roc_work);
 462	if (test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
 463		ieee80211_iterate_interfaces(mt76_hw(dev),
 464					     IEEE80211_IFACE_ITER_RESUME_ALL,
 465					     mt7925_roc_iter, (void *)phy);
 466}
 467EXPORT_SYMBOL_GPL(mt7925_roc_abort_sync);
 468
 469void mt7925_roc_work(struct work_struct *work)
 470{
 471	struct mt792x_phy *phy;
 472
 473	phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy,
 474						roc_work);
 475
 476	if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
 477		return;
 478
 479	mt792x_mutex_acquire(phy->dev);
 480	ieee80211_iterate_active_interfaces(phy->mt76->hw,
 481					    IEEE80211_IFACE_ITER_RESUME_ALL,
 482					    mt7925_roc_iter, phy);
 483	mt792x_mutex_release(phy->dev);
 484	ieee80211_remain_on_channel_expired(phy->mt76->hw);
 485}
 486
 487static int mt7925_abort_roc(struct mt792x_phy *phy,
 488			    struct mt792x_bss_conf *mconf)
 489{
 490	int err = 0;
 491
 492	timer_delete_sync(&phy->roc_timer);
 493	cancel_work_sync(&phy->roc_work);
 494
 495	mt792x_mutex_acquire(phy->dev);
 496	if (test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
 497		err = mt7925_mcu_abort_roc(phy, mconf, phy->roc_token_id);
 498	mt792x_mutex_release(phy->dev);
 499
 500	return err;
 501}
 502
 503static int mt7925_set_roc(struct mt792x_phy *phy,
 504			  struct mt792x_bss_conf *mconf,
 505			  struct ieee80211_channel *chan,
 506			  int duration,
 507			  enum mt7925_roc_req type)
 508{
 509	int err;
 510
 511	if (test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state))
 512		return -EBUSY;
 513
 514	phy->roc_grant = false;
 515
 516	err = mt7925_mcu_set_roc(phy, mconf, chan, duration, type,
 517				 ++phy->roc_token_id);
 518	if (err < 0) {
 519		clear_bit(MT76_STATE_ROC, &phy->mt76->state);
 520		goto out;
 521	}
 522
 523	if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, 4 * HZ)) {
 524		mt7925_mcu_abort_roc(phy, mconf, phy->roc_token_id);
 525		clear_bit(MT76_STATE_ROC, &phy->mt76->state);
 526		err = -ETIMEDOUT;
 527	}
 528
 529out:
 530	return err;
 531}
 532
 533static int mt7925_set_mlo_roc(struct mt792x_phy *phy,
 534			      struct mt792x_bss_conf *mconf,
 535			      u16 sel_links)
 536{
 537	int err;
 538
 539	if (WARN_ON_ONCE(test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state)))
 540		return -EBUSY;
 541
 542	phy->roc_grant = false;
 543
 544	err = mt7925_mcu_set_mlo_roc(mconf, sel_links, 5, ++phy->roc_token_id);
 545	if (err < 0) {
 546		clear_bit(MT76_STATE_ROC, &phy->mt76->state);
 547		goto out;
 548	}
 549
 550	if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, 4 * HZ)) {
 551		mt7925_mcu_abort_roc(phy, mconf, phy->roc_token_id);
 552		clear_bit(MT76_STATE_ROC, &phy->mt76->state);
 553		err = -ETIMEDOUT;
 554	}
 555
 556out:
 557	return err;
 558}
 559
 560static int mt7925_remain_on_channel(struct ieee80211_hw *hw,
 561				    struct ieee80211_vif *vif,
 562				    struct ieee80211_channel *chan,
 563				    int duration,
 564				    enum ieee80211_roc_type type)
 565{
 566	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
 567	struct mt792x_phy *phy = mt792x_hw_phy(hw);
 568	int err;
 569
 570	mt792x_mutex_acquire(phy->dev);
 571	err = mt7925_set_roc(phy, &mvif->bss_conf,
 572			     chan, duration, MT7925_ROC_REQ_ROC);
 573	mt792x_mutex_release(phy->dev);
 574
 575	return err;
 576}
 577
 578static int mt7925_cancel_remain_on_channel(struct ieee80211_hw *hw,
 579					   struct ieee80211_vif *vif)
 580{
 581	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
 582	struct mt792x_phy *phy = mt792x_hw_phy(hw);
 583
 584	return mt7925_abort_roc(phy, &mvif->bss_conf);
 585}
 586
 587static int mt7925_set_link_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 588			       struct ieee80211_vif *vif, struct ieee80211_sta *sta,
 589			       struct ieee80211_key_conf *key, int link_id)
 590{
 591	struct mt792x_dev *dev = mt792x_hw_dev(hw);
 592	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
 593	struct mt792x_sta *msta = sta ? (struct mt792x_sta *)sta->drv_priv :
 594				  &mvif->sta;
 595	struct ieee80211_bss_conf *link_conf;
 596	struct ieee80211_link_sta *link_sta;
 597	int idx = key->keyidx, err = 0;
 598	struct mt792x_link_sta *mlink;
 599	struct mt792x_bss_conf *mconf;
 600	struct mt76_wcid *wcid;
 601	u8 *wcid_keyidx;
 602
 603	link_conf = mt792x_vif_to_bss_conf(vif, link_id);
 604	link_sta = sta ? mt792x_sta_to_link_sta(vif, sta, link_id) : NULL;
 605	mconf = mt792x_vif_to_link(mvif, link_id);
 606	mlink = mt792x_sta_to_link(msta, link_id);
 607	wcid = &mlink->wcid;
 608	wcid_keyidx = &wcid->hw_key_idx;
 609
 610	/* fall back to sw encryption for unsupported ciphers */
 611	switch (key->cipher) {
 612	case WLAN_CIPHER_SUITE_AES_CMAC:
 613		key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
 614		wcid_keyidx = &wcid->hw_key_idx2;
 615		break;
 616	case WLAN_CIPHER_SUITE_WEP40:
 617	case WLAN_CIPHER_SUITE_WEP104:
 618		if (!mvif->wep_sta)
 619			return -EOPNOTSUPP;
 620		break;
 621	case WLAN_CIPHER_SUITE_TKIP:
 622	case WLAN_CIPHER_SUITE_CCMP:
 623	case WLAN_CIPHER_SUITE_CCMP_256:
 624	case WLAN_CIPHER_SUITE_GCMP:
 625	case WLAN_CIPHER_SUITE_GCMP_256:
 626	case WLAN_CIPHER_SUITE_SMS4:
 627		break;
 628	default:
 629		return -EOPNOTSUPP;
 630	}
 631
 632	if (cmd == SET_KEY && !mconf->mt76.cipher) {
 633		struct mt792x_phy *phy = mt792x_hw_phy(hw);
 634
 635		mconf->mt76.cipher = mt7925_mcu_get_cipher(key->cipher);
 636		mt7925_mcu_add_bss_info(phy, mconf->mt76.ctx, link_conf,
 637					link_sta, true);
 638	}
 639
 640	if (cmd == SET_KEY)
 641		*wcid_keyidx = idx;
 642	else if (idx == *wcid_keyidx)
 643		*wcid_keyidx = -1;
 644	else
 645		goto out;
 646
 647	mt76_wcid_key_setup(&dev->mt76, wcid,
 648			    cmd == SET_KEY ? key : NULL);
 649
 650	err = mt7925_mcu_add_key(&dev->mt76, vif, &mlink->bip,
 651				 key, MCU_UNI_CMD(STA_REC_UPDATE),
 652				 &mlink->wcid, cmd, msta);
 653
 654	if (err)
 655		goto out;
 656
 657	if (key->cipher == WLAN_CIPHER_SUITE_WEP104 ||
 658	    key->cipher == WLAN_CIPHER_SUITE_WEP40)
 659		err = mt7925_mcu_add_key(&dev->mt76, vif, &mvif->wep_sta->deflink.bip,
 660					 key, MCU_WMWA_UNI_CMD(STA_REC_UPDATE),
 661					 &mvif->wep_sta->deflink.wcid, cmd, msta);
 662out:
 663	return err;
 664}
 665
 666static int mt7925_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 667			  struct ieee80211_vif *vif, struct ieee80211_sta *sta,
 668			  struct ieee80211_key_conf *key)
 669{
 670	struct mt792x_dev *dev = mt792x_hw_dev(hw);
 671	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
 672	struct mt792x_sta *msta = sta ? (struct mt792x_sta *)sta->drv_priv :
 673				  &mvif->sta;
 674	int err;
 675
 676	/* The hardware does not support per-STA RX GTK, fallback
 677	 * to software mode for these.
 678	 */
 679	if ((vif->type == NL80211_IFTYPE_ADHOC ||
 680	     vif->type == NL80211_IFTYPE_MESH_POINT) &&
 681	    (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
 682	     key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
 683	    !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
 684		return -EOPNOTSUPP;
 685
 686	mt792x_mutex_acquire(dev);
 687
 688	if (ieee80211_vif_is_mld(vif)) {
 689		unsigned int link_id;
 690		unsigned long add;
 691
 692		add = key->link_id != -1 ? BIT(key->link_id) : msta->valid_links;
 693
 694		for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) {
 695			err = mt7925_set_link_key(hw, cmd, vif, sta, key, link_id);
 696			if (err < 0)
 697				break;
 698		}
 699	} else {
 700		err = mt7925_set_link_key(hw, cmd, vif, sta, key, vif->bss_conf.link_id);
 701	}
 702
 703	mt792x_mutex_release(dev);
 704
 705	return err;
 706}
 707
 708static void
 709mt7925_pm_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
 710{
 711	struct mt792x_dev *dev = priv;
 712	struct ieee80211_hw *hw = mt76_hw(dev);
 713	bool pm_enable = dev->pm.enable;
 714	int err;
 715
 716	err = mt7925_mcu_set_beacon_filter(dev, vif, pm_enable);
 717	if (err < 0)
 718		return;
 719
 720	if (pm_enable) {
 721		vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
 722		ieee80211_hw_set(hw, CONNECTION_MONITOR);
 723	} else {
 724		vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER;
 725		__clear_bit(IEEE80211_HW_CONNECTION_MONITOR, hw->flags);
 726	}
 727}
 728
 729static void
 730mt7925_sniffer_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
 731{
 732	struct mt792x_dev *dev = priv;
 733	struct ieee80211_hw *hw = mt76_hw(dev);
 734	struct mt76_connac_pm *pm = &dev->pm;
 735	bool monitor = !!(hw->conf.flags & IEEE80211_CONF_MONITOR);
 736
 737	mt7925_mcu_set_sniffer(dev, vif, monitor);
 738	pm->enable = pm->enable_user && !monitor;
 739	pm->ds_enable = pm->ds_enable_user && !monitor;
 740
 741	mt7925_mcu_set_deep_sleep(dev, pm->ds_enable);
 742
 743	if (monitor)
 744		mt7925_mcu_set_beacon_filter(dev, vif, false);
 745}
 746
 747void mt7925_set_runtime_pm(struct mt792x_dev *dev)
 748{
 749	struct ieee80211_hw *hw = mt76_hw(dev);
 750	struct mt76_connac_pm *pm = &dev->pm;
 751	bool monitor = !!(hw->conf.flags & IEEE80211_CONF_MONITOR);
 752
 753	pm->enable = pm->enable_user && !monitor;
 754	ieee80211_iterate_active_interfaces(hw,
 755					    IEEE80211_IFACE_ITER_RESUME_ALL,
 756					    mt7925_pm_interface_iter, dev);
 757	pm->ds_enable = pm->ds_enable_user && !monitor;
 758	mt7925_mcu_set_deep_sleep(dev, pm->ds_enable);
 759}
 760
 761static int mt7925_config(struct ieee80211_hw *hw, int radio_idx, u32 changed)
 762{
 763	struct mt792x_dev *dev = mt792x_hw_dev(hw);
 764	int ret = 0;
 765
 766	mt792x_mutex_acquire(dev);
 767
 768	if (changed & IEEE80211_CONF_CHANGE_POWER) {
 769		ret = mt7925_set_tx_sar_pwr(hw, NULL);
 770		if (ret)
 771			goto out;
 772	}
 773
 774	if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
 775		ieee80211_iterate_active_interfaces(hw,
 776						    IEEE80211_IFACE_ITER_RESUME_ALL,
 777						    mt7925_sniffer_interface_iter, dev);
 778	}
 779
 780out:
 781	mt792x_mutex_release(dev);
 782
 783	return ret;
 784}
 785
 786static void mt7925_configure_filter(struct ieee80211_hw *hw,
 787				    unsigned int changed_flags,
 788				    unsigned int *total_flags,
 789				    u64 multicast)
 790{
 791#define MT7925_FILTER_FCSFAIL    BIT(2)
 792#define MT7925_FILTER_CONTROL    BIT(5)
 793#define MT7925_FILTER_OTHER_BSS  BIT(6)
 794#define MT7925_FILTER_ENABLE     BIT(31)
 795	struct mt792x_dev *dev = mt792x_hw_dev(hw);
 796	u32 flags = MT7925_FILTER_ENABLE;
 797
 798#define MT7925_FILTER(_fif, _type) do {			\
 799		if (*total_flags & (_fif))		\
 800			flags |= MT7925_FILTER_##_type;	\
 801	} while (0)
 802
 803	MT7925_FILTER(FIF_FCSFAIL, FCSFAIL);
 804	MT7925_FILTER(FIF_CONTROL, CONTROL);
 805	MT7925_FILTER(FIF_OTHER_BSS, OTHER_BSS);
 806
 807	mt792x_mutex_acquire(dev);
 808	mt7925_mcu_set_rxfilter(dev, flags, 0, 0);
 809	mt792x_mutex_release(dev);
 810
 811	*total_flags &= (FIF_OTHER_BSS | FIF_FCSFAIL | FIF_CONTROL);
 812}
 813
 814static u8
 815mt7925_get_rates_table(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 816		       bool beacon, bool mcast)
 817{
 818	struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv;
 819	struct mt76_phy *mphy = hw->priv;
 820	u16 rate;
 821	u8 i, idx, ht;
 822
 823	rate = mt76_connac2_mac_tx_rate_val(mphy, &vif->bss_conf, beacon, mcast);
 824	ht = FIELD_GET(MT_TX_RATE_MODE, rate) > MT_PHY_TYPE_OFDM;
 825
 826	if (beacon && ht) {
 827		struct mt792x_dev *dev = mt792x_hw_dev(hw);
 828
 829		/* must odd index */
 830		idx = MT7925_BEACON_RATES_TBL + 2 * (mvif->idx % 20);
 831		mt7925_mac_set_fixed_rate_table(dev, idx, rate);
 832		return idx;
 833	}
 834
 835	idx = FIELD_GET(MT_TX_RATE_IDX, rate);
 836	for (i = 0; i < ARRAY_SIZE(mt76_rates); i++)
 837		if ((mt76_rates[i].hw_value & GENMASK(7, 0)) == idx)
 838			return MT792x_BASIC_RATES_TBL + i;
 839
 840	return mvif->basic_rates_idx;
 841}
 842
 843static int mt7925_mac_link_sta_add(struct mt76_dev *mdev,
 844				   struct ieee80211_vif *vif,
 845				   struct ieee80211_link_sta *link_sta)
 846{
 847	struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
 848	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
 849	struct ieee80211_bss_conf *link_conf;
 850	struct mt792x_bss_conf *mconf;
 851	u8 link_id = link_sta->link_id;
 852	struct mt792x_link_sta *mlink;
 853	struct mt792x_sta *msta;
 854	struct mt76_wcid *wcid;
 855	int ret, idx;
 856
 857	msta = (struct mt792x_sta *)link_sta->sta->drv_priv;
 858	mlink = mt792x_sta_to_link(msta, link_id);
 859
 860	idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT792x_WTBL_STA - 1);
 861	if (idx < 0)
 862		return -ENOSPC;
 863
 864	mconf = mt792x_vif_to_link(mvif, link_id);
 865	mt76_wcid_init(&mlink->wcid, 0);
 866	mlink->wcid.sta = 1;
 867	mlink->wcid.idx = idx;
 868	mlink->wcid.tx_info |= MT_WCID_TX_INFO_SET;
 869	mlink->last_txs = jiffies;
 870	mlink->wcid.link_id = link_sta->link_id;
 871	mlink->wcid.link_valid = !!link_sta->sta->valid_links;
 872	mlink->sta = msta;
 873
 874	wcid = &mlink->wcid;
 875	ewma_signal_init(&wcid->rssi);
 876	rcu_assign_pointer(dev->mt76.wcid[wcid->idx], wcid);
 877	mt76_wcid_init(wcid, 0);
 878	ewma_avg_signal_init(&mlink->avg_ack_signal);
 879	memset(mlink->airtime_ac, 0,
 880	       sizeof(msta->deflink.airtime_ac));
 881
 882	ret = mt76_connac_pm_wake(&dev->mphy, &dev->pm);
 883	if (ret)
 884		return ret;
 885
 886	mt7925_mac_wtbl_update(dev, idx,
 887			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
 888
 889	link_conf = mt792x_vif_to_bss_conf(vif, link_id);
 890
 891	/* should update bss info before STA add */
 892	if (vif->type == NL80211_IFTYPE_STATION && !link_sta->sta->tdls) {
 893		if (ieee80211_vif_is_mld(vif))
 894			mt7925_mcu_add_bss_info(&dev->phy, mconf->mt76.ctx,
 895						link_conf, link_sta, link_sta != mlink->pri_link);
 896		else
 897			mt7925_mcu_add_bss_info(&dev->phy, mconf->mt76.ctx,
 898						link_conf, link_sta, false);
 899	}
 900
 901	if (ieee80211_vif_is_mld(vif) &&
 902	    link_sta == mlink->pri_link) {
 903		ret = mt7925_mcu_sta_update(dev, link_sta, vif, true,
 904					    MT76_STA_INFO_STATE_NONE);
 905		if (ret)
 906			return ret;
 907	} else if (ieee80211_vif_is_mld(vif) &&
 908		   link_sta != mlink->pri_link) {
 909		ret = mt7925_mcu_sta_update(dev, mlink->pri_link, vif,
 910					    true, MT76_STA_INFO_STATE_ASSOC);
 911		if (ret)
 912			return ret;
 913
 914		ret = mt7925_mcu_sta_update(dev, link_sta, vif, true,
 915					    MT76_STA_INFO_STATE_ASSOC);
 916		if (ret)
 917			return ret;
 918	} else {
 919		ret = mt7925_mcu_sta_update(dev, link_sta, vif, true,
 920					    MT76_STA_INFO_STATE_NONE);
 921		if (ret)
 922			return ret;
 923	}
 924
 925	mt76_connac_power_save_sched(&dev->mphy, &dev->pm);
 926
 927	return 0;
 928}
 929
 930static int
 931mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
 932			 struct ieee80211_sta *sta, unsigned long new_links)
 933{
 934	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
 935	unsigned int link_id;
 936	int err = 0;
 937
 938	for_each_set_bit(link_id, &new_links, IEEE80211_MLD_MAX_NUM_LINKS) {
 939		struct ieee80211_link_sta *link_sta;
 940		struct mt792x_link_sta *mlink;
 941
 942		if (msta->deflink_id == IEEE80211_LINK_UNSPECIFIED) {
 943			mlink = &msta->deflink;
 944			msta->deflink_id = link_id;
 945		} else {
 946			mlink = devm_kzalloc(dev->mt76.dev, sizeof(*mlink), GFP_KERNEL);
 947			if (!mlink) {
 948				err = -ENOMEM;
 949				break;
 950			}
 951		}
 952
 953		msta->valid_links |= BIT(link_id);
 954		rcu_assign_pointer(msta->link[link_id], mlink);
 955		mlink->sta = msta;
 956		mlink->pri_link = &sta->deflink;
 957		mlink->wcid.def_wcid = &msta->deflink.wcid;
 958
 959		link_sta = mt792x_sta_to_link_sta(vif, sta, link_id);
 960		mt7925_mac_link_sta_add(&dev->mt76, vif, link_sta);
 961	}
 962
 963	return err;
 964}
 965
 966int mt7925_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 967		       struct ieee80211_sta *sta)
 968{
 969	struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
 970	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
 971	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
 972	int err;
 973
 974	msta->vif = mvif;
 975
 976	if (vif->type == NL80211_IFTYPE_STATION)
 977		mvif->wep_sta = msta;
 978
 979	if (ieee80211_vif_is_mld(vif)) {
 980		msta->deflink_id = IEEE80211_LINK_UNSPECIFIED;
 981
 982		err = mt7925_mac_sta_add_links(dev, vif, sta, sta->valid_links);
 983	} else {
 984		err = mt7925_mac_link_sta_add(mdev, vif, &sta->deflink);
 985	}
 986
 987	return err;
 988}
 989EXPORT_SYMBOL_GPL(mt7925_mac_sta_add);
 990
 991static void
 992mt7925_mac_set_links(struct mt76_dev *mdev, struct ieee80211_vif *vif)
 993{
 994	struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
 995	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
 996	struct ieee80211_bss_conf *link_conf =
 997		mt792x_vif_to_bss_conf(vif, mvif->deflink_id);
 998	struct cfg80211_chan_def *chandef = &link_conf->chanreq.oper;
 999	enum nl80211_band band = chandef->chan->band, secondary_band;
1000
1001	u16 sel_links = mt76_select_links(vif, 2);
1002	u8 secondary_link_id = __ffs(~BIT(mvif->deflink_id) & sel_links);
1003
1004	if (!ieee80211_vif_is_mld(vif) || hweight16(sel_links) < 2)
1005		return;
1006
1007	link_conf = mt792x_vif_to_bss_conf(vif, secondary_link_id);
1008	secondary_band = link_conf->chanreq.oper.chan->band;
1009
1010	if (band == NL80211_BAND_2GHZ ||
1011	    (band == NL80211_BAND_5GHZ && secondary_band == NL80211_BAND_6GHZ)) {
1012		mt7925_abort_roc(mvif->phy, &mvif->bss_conf);
1013
1014		mt792x_mutex_acquire(dev);
1015
1016		mt7925_set_mlo_roc(mvif->phy, &mvif->bss_conf, sel_links);
1017
1018		mt792x_mutex_release(dev);
1019	}
1020
1021	ieee80211_set_active_links_async(vif, sel_links);
1022}
1023
1024static void mt7925_mac_link_sta_assoc(struct mt76_dev *mdev,
1025				      struct ieee80211_vif *vif,
1026				      struct ieee80211_link_sta *link_sta)
1027{
1028	struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
1029	struct ieee80211_bss_conf *link_conf;
1030	struct mt792x_link_sta *mlink;
1031	struct mt792x_sta *msta;
1032
1033	msta = (struct mt792x_sta *)link_sta->sta->drv_priv;
1034	mlink = mt792x_sta_to_link(msta, link_sta->link_id);
1035
1036	mt792x_mutex_acquire(dev);
1037
1038	if (ieee80211_vif_is_mld(vif)) {
1039		link_conf = mt792x_vif_to_bss_conf(vif, msta->deflink_id);
1040	} else {
1041		link_conf = mt792x_vif_to_bss_conf(vif, vif->bss_conf.link_id);
1042	}
1043
1044	if (vif->type == NL80211_IFTYPE_STATION && !link_sta->sta->tdls) {
1045		struct mt792x_bss_conf *mconf;
1046
1047		mconf = mt792x_link_conf_to_mconf(link_conf);
1048		mt7925_mcu_add_bss_info(&dev->phy, mconf->mt76.ctx,
1049					link_conf, link_sta, true);
1050	}
1051
1052	ewma_avg_signal_init(&mlink->avg_ack_signal);
1053
1054	mt7925_mac_wtbl_update(dev, mlink->wcid.idx,
1055			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
1056	memset(mlink->airtime_ac, 0, sizeof(mlink->airtime_ac));
1057
1058	mt7925_mcu_sta_update(dev, link_sta, vif, true, MT76_STA_INFO_STATE_ASSOC);
1059
1060	mt792x_mutex_release(dev);
1061}
1062
1063int mt7925_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif,
1064			 struct ieee80211_sta *sta, enum mt76_sta_event ev)
1065{
1066	struct ieee80211_link_sta *link_sta = &sta->deflink;
1067
1068	if (ev != MT76_STA_EVENT_ASSOC)
1069		return 0;
1070
1071	if (ieee80211_vif_is_mld(vif)) {
1072		struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
1073
1074		link_sta = mt792x_sta_to_link_sta(vif, sta, msta->deflink_id);
1075		mt7925_mac_set_links(mdev, vif);
1076	}
1077
1078	mt7925_mac_link_sta_assoc(mdev, vif, link_sta);
1079
1080	return 0;
1081}
1082EXPORT_SYMBOL_GPL(mt7925_mac_sta_event);
1083
1084static void mt7925_mac_link_sta_remove(struct mt76_dev *mdev,
1085				       struct ieee80211_vif *vif,
1086				       struct ieee80211_link_sta *link_sta)
1087{
1088	struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
1089	struct ieee80211_bss_conf *link_conf;
1090	u8 link_id = link_sta->link_id;
1091	struct mt792x_link_sta *mlink;
1092	struct mt792x_sta *msta;
1093
1094	msta = (struct mt792x_sta *)link_sta->sta->drv_priv;
1095	mlink = mt792x_sta_to_link(msta, link_id);
1096
1097	mt7925_roc_abort_sync(dev);
1098
1099	mt76_connac_free_pending_tx_skbs(&dev->pm, &mlink->wcid);
1100	mt76_connac_pm_wake(&dev->mphy, &dev->pm);
1101
1102	mt7925_mcu_sta_update(dev, link_sta, vif, false,
1103			      MT76_STA_INFO_STATE_NONE);
1104	mt7925_mac_wtbl_update(dev, mlink->wcid.idx,
1105			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
1106
1107	link_conf = mt792x_vif_to_bss_conf(vif, link_id);
1108
1109	if (vif->type == NL80211_IFTYPE_STATION && !link_sta->sta->tdls) {
1110		struct mt792x_bss_conf *mconf;
1111
1112		mconf = mt792x_link_conf_to_mconf(link_conf);
1113
1114		if (ieee80211_vif_is_mld(vif))
1115			mt792x_mac_link_bss_remove(dev, mconf, mlink);
1116		else
1117			mt7925_mcu_add_bss_info(&dev->phy, mconf->mt76.ctx, link_conf,
1118						link_sta, false);
1119	}
1120
1121	spin_lock_bh(&mdev->sta_poll_lock);
1122	if (!list_empty(&mlink->wcid.poll_list))
1123		list_del_init(&mlink->wcid.poll_list);
1124	spin_unlock_bh(&mdev->sta_poll_lock);
1125
1126	mt76_connac_power_save_sched(&dev->mphy, &dev->pm);
1127}
1128
1129static int
1130mt7925_mac_sta_remove_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
1131			    struct ieee80211_sta *sta, unsigned long old_links)
1132{
1133	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
1134	struct mt76_dev *mdev = &dev->mt76;
1135	struct mt76_wcid *wcid;
1136	unsigned int link_id;
1137
1138	/* clean up bss before starec */
1139	for_each_set_bit(link_id, &old_links, IEEE80211_MLD_MAX_NUM_LINKS) {
1140		struct ieee80211_link_sta *link_sta;
1141		struct ieee80211_bss_conf *link_conf;
1142		struct mt792x_bss_conf *mconf;
1143		struct mt792x_link_sta *mlink;
1144
1145		if (vif->type == NL80211_IFTYPE_AP)
1146			break;
1147
1148		link_sta = mt792x_sta_to_link_sta(vif, sta, link_id);
1149		if (!link_sta)
1150			continue;
1151
1152		mlink = mt792x_sta_to_link(msta, link_id);
1153		if (!mlink)
1154			continue;
1155
1156		link_conf = mt792x_vif_to_bss_conf(vif, link_id);
1157		if (!link_conf)
1158			continue;
1159
1160		mconf = mt792x_link_conf_to_mconf(link_conf);
1161
1162		mt7925_mcu_add_bss_info(&dev->phy, mconf->mt76.ctx, link_conf,
1163					link_sta, false);
1164	}
1165
1166	for_each_set_bit(link_id, &old_links, IEEE80211_MLD_MAX_NUM_LINKS) {
1167		struct ieee80211_link_sta *link_sta;
1168		struct mt792x_link_sta *mlink;
1169
1170		link_sta = mt792x_sta_to_link_sta(vif, sta, link_id);
1171		if (!link_sta)
1172			continue;
1173
1174		mlink = mt792x_sta_to_link(msta, link_id);
1175		if (!mlink)
1176			continue;
1177
1178		mt7925_mac_link_sta_remove(&dev->mt76, vif, link_sta);
1179
1180		wcid = &mlink->wcid;
1181		rcu_assign_pointer(msta->link[link_id], NULL);
1182		msta->valid_links &= ~BIT(link_id);
1183		mlink->sta = NULL;
1184		mlink->pri_link = NULL;
1185
1186		if (link_sta != mlink->pri_link) {
1187			mt76_wcid_cleanup(mdev, wcid);
1188			mt76_wcid_mask_clear(mdev->wcid_mask, wcid->idx);
1189		}
1190
1191		if (msta->deflink_id == link_id)
1192			msta->deflink_id = IEEE80211_LINK_UNSPECIFIED;
1193	}
1194
1195	return 0;
1196}
1197
1198void mt7925_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
1199			   struct ieee80211_sta *sta)
1200{
1201	struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
1202	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
1203	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1204	unsigned long rem;
1205
1206	rem = ieee80211_vif_is_mld(vif) ? msta->valid_links : BIT(0);
1207
1208	mt7925_mac_sta_remove_links(dev, vif, sta, rem);
1209
1210	if (ieee80211_vif_is_mld(vif))
1211		mt7925_mcu_del_dev(mdev, vif);
1212
1213	if (vif->type == NL80211_IFTYPE_STATION) {
1214		mvif->wep_sta = NULL;
1215		ewma_rssi_init(&mvif->bss_conf.rssi);
1216	}
1217
1218	mvif->mlo_pm_state = MT792x_MLO_LINK_DISASSOC;
1219}
1220EXPORT_SYMBOL_GPL(mt7925_mac_sta_remove);
1221
1222static int mt7925_set_rts_threshold(struct ieee80211_hw *hw, int radio_idx,
1223				    u32 val)
1224{
1225	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1226
1227	mt792x_mutex_acquire(dev);
1228	mt7925_mcu_set_rts_thresh(&dev->phy, val);
1229	mt792x_mutex_release(dev);
1230
1231	return 0;
1232}
1233
1234static int
1235mt7925_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1236		    struct ieee80211_ampdu_params *params)
1237{
1238	enum ieee80211_ampdu_mlme_action action = params->action;
1239	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1240	struct ieee80211_sta *sta = params->sta;
1241	struct ieee80211_txq *txq = sta->txq[params->tid];
1242	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
1243	u16 tid = params->tid;
1244	u16 ssn = params->ssn;
1245	struct mt76_txq *mtxq;
1246	int ret = 0;
1247
1248	if (!txq)
1249		return -EINVAL;
1250
1251	mtxq = (struct mt76_txq *)txq->drv_priv;
1252
1253	mt792x_mutex_acquire(dev);
1254	switch (action) {
1255	case IEEE80211_AMPDU_RX_START:
1256		mt76_rx_aggr_start(&dev->mt76, &msta->deflink.wcid, tid, ssn,
1257				   params->buf_size);
1258		mt7925_mcu_uni_rx_ba(dev, params, true);
1259		break;
1260	case IEEE80211_AMPDU_RX_STOP:
1261		mt76_rx_aggr_stop(&dev->mt76, &msta->deflink.wcid, tid);
1262		mt7925_mcu_uni_rx_ba(dev, params, false);
1263		break;
1264	case IEEE80211_AMPDU_TX_OPERATIONAL:
1265		mtxq->aggr = true;
1266		mtxq->send_bar = false;
1267		mt7925_mcu_uni_tx_ba(dev, params, true);
1268		break;
1269	case IEEE80211_AMPDU_TX_STOP_FLUSH:
1270	case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1271		mtxq->aggr = false;
1272		clear_bit(tid, &msta->deflink.wcid.ampdu_state);
1273		mt7925_mcu_uni_tx_ba(dev, params, false);
1274		break;
1275	case IEEE80211_AMPDU_TX_START:
1276		set_bit(tid, &msta->deflink.wcid.ampdu_state);
1277		ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;
1278		break;
1279	case IEEE80211_AMPDU_TX_STOP_CONT:
1280		mtxq->aggr = false;
1281		clear_bit(tid, &msta->deflink.wcid.ampdu_state);
1282		mt7925_mcu_uni_tx_ba(dev, params, false);
1283		ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1284		break;
1285	}
1286	mt792x_mutex_release(dev);
1287
1288	return ret;
1289}
1290
1291static void
1292mt7925_mlo_pm_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
1293{
1294	struct mt792x_dev *dev = priv;
1295	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1296	unsigned long valid = ieee80211_vif_is_mld(vif) ?
1297				    mvif->valid_links : BIT(0);
1298	struct ieee80211_bss_conf *bss_conf;
1299	int i;
1300
1301	if (mvif->mlo_pm_state != MT792x_MLO_CHANGED_PS)
1302		return;
1303
1304	mt792x_mutex_acquire(dev);
1305	for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
1306		bss_conf = mt792x_vif_to_bss_conf(vif, i);
1307		mt7925_mcu_uni_bss_ps(dev, bss_conf);
1308	}
1309	mt792x_mutex_release(dev);
1310}
1311
1312void mt7925_mlo_pm_work(struct work_struct *work)
1313{
1314	struct mt792x_dev *dev = container_of(work, struct mt792x_dev,
1315					      mlo_pm_work.work);
1316	struct ieee80211_hw *hw = mt76_hw(dev);
1317
1318	ieee80211_iterate_active_interfaces(hw,
1319					    IEEE80211_IFACE_ITER_RESUME_ALL,
1320					    mt7925_mlo_pm_iter, dev);
1321}
1322
1323void mt7925_scan_work(struct work_struct *work)
1324{
1325	struct mt792x_phy *phy;
1326
1327	phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy,
1328						scan_work.work);
1329
1330	while (true) {
1331		struct sk_buff *skb;
1332		struct tlv *tlv;
1333		int tlv_len;
1334
1335		spin_lock_bh(&phy->dev->mt76.lock);
1336		skb = __skb_dequeue(&phy->scan_event_list);
1337		spin_unlock_bh(&phy->dev->mt76.lock);
1338
1339		if (!skb)
1340			break;
1341
1342		skb_pull(skb, sizeof(struct mt7925_mcu_rxd) + 4);
1343		tlv = (struct tlv *)skb->data;
1344		tlv_len = skb->len;
1345
1346		while (tlv_len > 0 && le16_to_cpu(tlv->len) <= tlv_len) {
1347			struct mt7925_mcu_scan_chinfo_event *evt;
1348
1349			switch (le16_to_cpu(tlv->tag)) {
1350			case UNI_EVENT_SCAN_DONE_BASIC:
1351				if (test_and_clear_bit(MT76_HW_SCANNING, &phy->mt76->state)) {
1352					struct cfg80211_scan_info info = {
1353						.aborted = false,
1354					};
1355					ieee80211_scan_completed(phy->mt76->hw, &info);
1356				}
1357				break;
1358			case UNI_EVENT_SCAN_DONE_CHNLINFO:
1359				evt = (struct mt7925_mcu_scan_chinfo_event *)tlv->data;
1360
1361				mt7925_regd_change(phy, evt->alpha2);
1362
1363				break;
1364			case UNI_EVENT_SCAN_DONE_NLO:
1365				ieee80211_sched_scan_results(phy->mt76->hw);
1366				break;
1367			default:
1368				break;
1369			}
1370
1371			tlv_len -= le16_to_cpu(tlv->len);
1372			tlv = (struct tlv *)((char *)(tlv) + le16_to_cpu(tlv->len));
1373		}
1374
1375		dev_kfree_skb(skb);
1376	}
1377}
1378
1379static int
1380mt7925_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1381	       struct ieee80211_scan_request *req)
1382{
1383	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1384	struct mt76_phy *mphy = hw->priv;
1385	int err;
1386
1387	mt792x_mutex_acquire(dev);
1388	err = mt7925_mcu_hw_scan(mphy, vif, req);
1389	mt792x_mutex_release(dev);
1390
1391	return err;
1392}
1393
1394static void
1395mt7925_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1396{
1397	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1398	struct mt76_phy *mphy = hw->priv;
1399
1400	mt792x_mutex_acquire(dev);
1401	mt7925_mcu_cancel_hw_scan(mphy, vif);
1402	mt792x_mutex_release(dev);
1403}
1404
1405static int
1406mt7925_start_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1407			struct cfg80211_sched_scan_request *req,
1408			struct ieee80211_scan_ies *ies)
1409{
1410	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1411	struct mt76_phy *mphy = hw->priv;
1412	int err;
1413
1414	mt792x_mutex_acquire(dev);
1415
1416	err = mt7925_mcu_sched_scan_req(mphy, vif, req, ies);
1417	if (err < 0)
1418		goto out;
1419
1420	err = mt7925_mcu_sched_scan_enable(mphy, vif, true);
1421out:
1422	mt792x_mutex_release(dev);
1423
1424	return err;
1425}
1426
1427static int
1428mt7925_stop_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1429{
1430	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1431	struct mt76_phy *mphy = hw->priv;
1432	int err;
1433
1434	mt792x_mutex_acquire(dev);
1435	err = mt7925_mcu_sched_scan_enable(mphy, vif, false);
1436	mt792x_mutex_release(dev);
1437
1438	return err;
1439}
1440
1441static int
1442mt7925_set_antenna(struct ieee80211_hw *hw, int radio_idx,
1443		   u32 tx_ant, u32 rx_ant)
1444{
1445	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1446	struct mt792x_phy *phy = mt792x_hw_phy(hw);
1447	int max_nss = hweight8(hw->wiphy->available_antennas_tx);
1448
1449	if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss)
1450		return -EINVAL;
1451
1452	if ((BIT(hweight8(tx_ant)) - 1) != tx_ant)
1453		tx_ant = BIT(ffs(tx_ant) - 1) - 1;
1454
1455	mt792x_mutex_acquire(dev);
1456
1457	phy->mt76->antenna_mask = tx_ant;
1458	phy->mt76->chainmask = tx_ant;
1459
1460	mt76_set_stream_caps(phy->mt76, true);
1461	mt7925_set_stream_he_eht_caps(phy);
1462
1463	/* TODO: update bmc_wtbl spe_idx when antenna changes */
1464	mt792x_mutex_release(dev);
1465
1466	return 0;
1467}
1468
1469#ifdef CONFIG_PM
1470static int mt7925_suspend(struct ieee80211_hw *hw,
1471			  struct cfg80211_wowlan *wowlan)
1472{
1473	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1474	struct mt792x_phy *phy = mt792x_hw_phy(hw);
1475
1476	cancel_delayed_work_sync(&phy->scan_work);
1477	cancel_delayed_work_sync(&phy->mt76->mac_work);
1478
1479	cancel_delayed_work_sync(&dev->pm.ps_work);
1480	mt76_connac_free_pending_tx_skbs(&dev->pm, NULL);
1481
1482	mt792x_mutex_acquire(dev);
1483
1484	clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
1485	ieee80211_iterate_active_interfaces(hw,
1486					    IEEE80211_IFACE_ITER_RESUME_ALL,
1487					    mt7925_mcu_set_suspend_iter,
1488					    &dev->mphy);
1489
1490	mt792x_mutex_release(dev);
1491
1492	return 0;
1493}
1494
1495static int mt7925_resume(struct ieee80211_hw *hw)
1496{
1497	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1498	struct mt792x_phy *phy = mt792x_hw_phy(hw);
1499
1500	mt792x_mutex_acquire(dev);
1501
1502	set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
1503	ieee80211_iterate_active_interfaces(hw,
1504					    IEEE80211_IFACE_ITER_RESUME_ALL,
1505					    mt7925_mcu_set_suspend_iter,
1506					    &dev->mphy);
1507
1508	ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
1509				     MT792x_WATCHDOG_TIME);
1510
1511	mt792x_mutex_release(dev);
1512
1513	return 0;
1514}
1515
1516static void mt7925_set_rekey_data(struct ieee80211_hw *hw,
1517				  struct ieee80211_vif *vif,
1518				  struct cfg80211_gtk_rekey_data *data)
1519{
1520	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1521
1522	mt792x_mutex_acquire(dev);
1523	mt76_connac_mcu_update_gtk_rekey(hw, vif, data);
1524	mt792x_mutex_release(dev);
1525}
1526#endif /* CONFIG_PM */
1527
1528static void mt7925_sta_set_decap_offload(struct ieee80211_hw *hw,
1529					 struct ieee80211_vif *vif,
1530					 struct ieee80211_sta *sta,
1531					 bool enabled)
1532{
1533	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
1534	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1535	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1536	unsigned long valid = mvif->valid_links;
1537	u8 i;
1538
1539	if (!msta->vif)
1540		return;
1541
1542	mt792x_mutex_acquire(dev);
1543
1544	valid = ieee80211_vif_is_mld(vif) ? mvif->valid_links : BIT(0);
1545
1546	for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
1547		struct mt792x_link_sta *mlink;
1548
1549		mlink = mt792x_sta_to_link(msta, i);
1550
1551		if (enabled)
1552			set_bit(MT_WCID_FLAG_HDR_TRANS, &mlink->wcid.flags);
1553		else
1554			clear_bit(MT_WCID_FLAG_HDR_TRANS, &mlink->wcid.flags);
1555
1556		if (!mlink->wcid.sta)
1557			continue;
1558
1559		mt7925_mcu_wtbl_update_hdr_trans(dev, vif, sta, i);
1560	}
1561
1562	mt792x_mutex_release(dev);
1563}
1564
1565#if IS_ENABLED(CONFIG_IPV6)
1566static void __mt7925_ipv6_addr_change(struct ieee80211_hw *hw,
1567				      struct ieee80211_bss_conf *link_conf,
1568				      struct inet6_dev *idev)
1569{
1570	struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf);
1571	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1572	struct inet6_ifaddr *ifa;
1573	struct sk_buff *skb;
1574	u8 idx = 0;
1575
1576	struct {
1577		struct {
1578			u8 bss_idx;
1579			u8 pad[3];
1580		} __packed hdr;
1581		struct mt7925_arpns_tlv arpns;
1582		struct in6_addr ns_addrs[IEEE80211_BSS_ARP_ADDR_LIST_LEN];
1583	} req_hdr = {
1584		.hdr = {
1585			.bss_idx = mconf->mt76.idx,
1586		},
1587		.arpns = {
1588			.tag = cpu_to_le16(UNI_OFFLOAD_OFFLOAD_ND),
1589			.len = cpu_to_le16(sizeof(req_hdr) - 4),
1590			.enable = true,
1591		},
1592	};
1593
1594	read_lock_bh(&idev->lock);
1595	list_for_each_entry(ifa, &idev->addr_list, if_list) {
1596		if (ifa->flags & IFA_F_TENTATIVE)
1597			continue;
1598		req_hdr.ns_addrs[idx] = ifa->addr;
1599		if (++idx >= IEEE80211_BSS_ARP_ADDR_LIST_LEN)
1600			break;
1601	}
1602	read_unlock_bh(&idev->lock);
1603
1604	if (!idx)
1605		return;
1606
1607	req_hdr.arpns.ips_num = idx;
1608
1609	skb = __mt76_mcu_msg_alloc(&dev->mt76, NULL, sizeof(req_hdr),
1610				   0, GFP_ATOMIC);
1611	if (!skb)
1612		return;
1613
1614	skb_put_data(skb, &req_hdr, sizeof(req_hdr));
1615
1616	skb_queue_tail(&dev->ipv6_ns_list, skb);
1617
1618	ieee80211_queue_work(dev->mt76.hw, &dev->ipv6_ns_work);
1619}
1620
1621static void mt7925_ipv6_addr_change(struct ieee80211_hw *hw,
1622				    struct ieee80211_vif *vif,
1623				    struct inet6_dev *idev)
1624{
1625	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1626	unsigned long valid = ieee80211_vif_is_mld(vif) ?
1627			      mvif->valid_links : BIT(0);
1628	struct ieee80211_bss_conf *bss_conf;
1629	int i;
1630
1631	for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
1632		bss_conf = mt792x_vif_to_bss_conf(vif, i);
1633		__mt7925_ipv6_addr_change(hw, bss_conf, idev);
1634	}
1635}
1636
1637#endif
1638
1639int mt7925_set_tx_sar_pwr(struct ieee80211_hw *hw,
1640			  const struct cfg80211_sar_specs *sar)
1641{
1642	struct mt76_phy *mphy = hw->priv;
1643
1644	if (sar) {
1645		int err = mt76_init_sar_power(hw, sar);
1646
1647		if (err)
1648			return err;
1649	}
1650	mt792x_init_acpi_sar_power(mt792x_hw_phy(hw), !sar);
1651
1652	return mt7925_mcu_set_rate_txpower(mphy);
1653}
1654
1655static int mt7925_set_sar_specs(struct ieee80211_hw *hw,
1656				const struct cfg80211_sar_specs *sar)
1657{
1658	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1659	int err;
1660
1661	mt792x_mutex_acquire(dev);
1662	err = mt7925_set_tx_sar_pwr(hw, sar);
1663	mt792x_mutex_release(dev);
1664
1665	return err;
1666}
1667
1668static void
1669mt7925_channel_switch_beacon(struct ieee80211_hw *hw,
1670			     struct ieee80211_vif *vif,
1671			     struct cfg80211_chan_def *chandef)
1672{
1673	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1674
1675	mt792x_mutex_acquire(dev);
1676	mt7925_mcu_uni_add_beacon_offload(dev, hw, vif, true);
1677	mt792x_mutex_release(dev);
1678}
1679
1680static int
1681mt7925_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1682	       unsigned int link_id, u16 queue,
1683	       const struct ieee80211_tx_queue_params *params)
1684{
1685	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1686	struct mt792x_bss_conf *mconf = mt792x_vif_to_link(mvif, link_id);
1687	static const u8 mq_to_aci[] = {
1688		    [IEEE80211_AC_VO] = 3,
1689		    [IEEE80211_AC_VI] = 2,
1690		    [IEEE80211_AC_BE] = 0,
1691		    [IEEE80211_AC_BK] = 1,
1692	};
1693
1694	/* firmware uses access class index */
1695	mconf->queue_params[mq_to_aci[queue]] = *params;
1696
1697	return 0;
1698}
1699
1700static int
1701mt7925_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1702		struct ieee80211_bss_conf *link_conf)
1703{
1704	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1705	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1706	int err;
1707
1708	mt792x_mutex_acquire(dev);
1709
1710	err = mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx,
1711				      link_conf, NULL, true);
1712	if (err)
1713		goto out;
1714
1715	err = mt7925_mcu_set_bss_pm(dev, link_conf, true);
1716	if (err)
1717		goto out;
1718
1719	err = mt7925_mcu_sta_update(dev, NULL, vif, true,
1720				    MT76_STA_INFO_STATE_NONE);
1721out:
1722	mt792x_mutex_release(dev);
1723
1724	return err;
1725}
1726
1727static void
1728mt7925_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1729	       struct ieee80211_bss_conf *link_conf)
1730{
1731	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1732	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1733	int err;
1734
1735	mt792x_mutex_acquire(dev);
1736
1737	err = mt7925_mcu_set_bss_pm(dev, link_conf, false);
1738	if (err)
1739		goto out;
1740
1741	mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx, link_conf,
1742				NULL, false);
1743
1744out:
1745	mt792x_mutex_release(dev);
1746}
1747
1748static int
1749mt7925_add_chanctx(struct ieee80211_hw *hw,
1750		   struct ieee80211_chanctx_conf *ctx)
1751{
1752	return 0;
1753}
1754
1755static void
1756mt7925_remove_chanctx(struct ieee80211_hw *hw,
1757		      struct ieee80211_chanctx_conf *ctx)
1758{
1759}
1760
1761static void
1762mt7925_change_chanctx(struct ieee80211_hw *hw,
1763		      struct ieee80211_chanctx_conf *ctx,
1764		      u32 changed)
1765{
1766	struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv;
1767	struct mt792x_phy *phy = mt792x_hw_phy(hw);
1768	struct mt792x_bss_conf *mconf;
1769	struct ieee80211_vif *vif;
1770	struct mt792x_vif *mvif;
1771
1772	if (!mctx->bss_conf)
1773		return;
1774
1775	mconf = mctx->bss_conf;
1776	mvif = mconf->vif;
1777	vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv);
1778
1779	mt792x_mutex_acquire(phy->dev);
1780	if (vif->type == NL80211_IFTYPE_MONITOR) {
1781		mt7925_mcu_set_sniffer(mvif->phy->dev, vif, true);
1782		mt7925_mcu_config_sniffer(mvif, ctx);
1783	} else {
1784		if (ieee80211_vif_is_mld(vif)) {
1785			unsigned long valid = mvif->valid_links;
1786			u8 i;
1787
1788			for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
1789				mconf = mt792x_vif_to_link(mvif, i);
1790				if (mconf && mconf->mt76.ctx == ctx)
1791					break;
1792			}
1793
1794		} else {
1795			mconf = &mvif->bss_conf;
1796		}
1797
1798		if (mconf) {
1799			struct ieee80211_bss_conf *link_conf;
1800
1801			link_conf = mt792x_vif_to_bss_conf(vif, mconf->link_id);
1802			mt7925_mcu_set_chctx(mvif->phy->mt76, &mconf->mt76,
1803					     link_conf, ctx);
1804
1805			if (changed & IEEE80211_CHANCTX_CHANGE_PUNCTURING)
1806				mt7925_mcu_set_eht_pp(mvif->phy->mt76, &mconf->mt76,
1807						      link_conf, ctx);
1808		}
1809	}
1810
1811	mt792x_mutex_release(phy->dev);
1812}
1813
1814static void mt7925_mgd_prepare_tx(struct ieee80211_hw *hw,
1815				  struct ieee80211_vif *vif,
1816				  struct ieee80211_prep_tx_info *info)
1817{
1818	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1819	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1820	u16 duration = info->duration ? info->duration :
1821		       jiffies_to_msecs(HZ);
1822
1823	mt792x_mutex_acquire(dev);
1824	mt7925_set_roc(mvif->phy, &mvif->bss_conf,
1825		       mvif->bss_conf.mt76.ctx->def.chan, duration,
1826		       MT7925_ROC_REQ_JOIN);
1827	mt792x_mutex_release(dev);
1828}
1829
1830static void mt7925_mgd_complete_tx(struct ieee80211_hw *hw,
1831				   struct ieee80211_vif *vif,
1832				   struct ieee80211_prep_tx_info *info)
1833{
1834	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1835
1836	mt7925_abort_roc(mvif->phy, &mvif->bss_conf);
1837}
1838
1839static void mt7925_vif_cfg_changed(struct ieee80211_hw *hw,
1840				   struct ieee80211_vif *vif,
1841				   u64 changed)
1842{
1843	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1844	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1845	unsigned long valid = ieee80211_vif_is_mld(vif) ?
1846				      mvif->valid_links : BIT(0);
1847	struct ieee80211_bss_conf *bss_conf;
1848	int i;
1849
1850	mt792x_mutex_acquire(dev);
1851
1852	if (changed & BSS_CHANGED_ASSOC) {
1853		mt7925_mcu_sta_update(dev, NULL, vif, true,
1854				      MT76_STA_INFO_STATE_ASSOC);
1855		mt7925_mcu_set_beacon_filter(dev, vif, vif->cfg.assoc);
1856
1857		if (ieee80211_vif_is_mld(vif))
1858			mvif->mlo_pm_state = MT792x_MLO_LINK_ASSOC;
1859	}
1860
1861	if (changed & BSS_CHANGED_ARP_FILTER) {
1862		for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
1863			bss_conf = mt792x_vif_to_bss_conf(vif, i);
1864			mt7925_mcu_update_arp_filter(&dev->mt76, bss_conf);
1865		}
1866	}
1867
1868	if (changed & BSS_CHANGED_PS) {
1869		if (hweight16(mvif->valid_links) < 2) {
1870			/* legacy */
1871			bss_conf = &vif->bss_conf;
1872			mt7925_mcu_uni_bss_ps(dev, bss_conf);
1873		} else {
1874			if (mvif->mlo_pm_state == MT792x_MLO_LINK_ASSOC) {
1875				mvif->mlo_pm_state = MT792x_MLO_CHANGED_PS_PENDING;
1876			} else if (mvif->mlo_pm_state == MT792x_MLO_CHANGED_PS) {
1877				for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
1878					bss_conf = mt792x_vif_to_bss_conf(vif, i);
1879					mt7925_mcu_uni_bss_ps(dev, bss_conf);
1880				}
1881			}
1882		}
1883	}
1884
1885	mt792x_mutex_release(dev);
1886}
1887
1888static void mt7925_link_info_changed(struct ieee80211_hw *hw,
1889				     struct ieee80211_vif *vif,
1890				     struct ieee80211_bss_conf *info,
1891				     u64 changed)
1892{
1893	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1894	struct mt792x_phy *phy = mt792x_hw_phy(hw);
1895	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1896	struct mt792x_bss_conf *mconf;
1897	struct ieee80211_bss_conf *link_conf;
1898
1899	mconf = mt792x_vif_to_link(mvif, info->link_id);
1900	link_conf = mt792x_vif_to_bss_conf(vif, mconf->link_id);
1901
1902	mt792x_mutex_acquire(dev);
1903
1904	if (changed & BSS_CHANGED_ERP_SLOT) {
1905		int slottime = info->use_short_slot ? 9 : 20;
1906
1907		if (slottime != phy->slottime) {
1908			phy->slottime = slottime;
1909			mt7925_mcu_set_timing(phy, info);
1910		}
1911	}
1912
1913	if (changed & BSS_CHANGED_MCAST_RATE)
1914		mconf->mt76.mcast_rates_idx =
1915				mt7925_get_rates_table(hw, vif, false, true);
1916
1917	if (changed & BSS_CHANGED_BASIC_RATES)
1918		mconf->mt76.basic_rates_idx =
1919				mt7925_get_rates_table(hw, vif, false, false);
1920
1921	if (changed & (BSS_CHANGED_BEACON |
1922		       BSS_CHANGED_BEACON_ENABLED)) {
1923		mconf->mt76.beacon_rates_idx =
1924				mt7925_get_rates_table(hw, vif, true, false);
1925
1926		mt7925_mcu_uni_add_beacon_offload(dev, hw, vif,
1927						  info->enable_beacon);
1928	}
1929
1930	/* ensure that enable txcmd_mode after bss_info */
1931	if (changed & (BSS_CHANGED_QOS | BSS_CHANGED_BEACON_ENABLED))
1932		mt7925_mcu_set_tx(dev, info);
1933
1934	if (mvif->mlo_pm_state == MT792x_MLO_CHANGED_PS_PENDING) {
1935		/* Indicate the secondary setup done */
1936		mt7925_mcu_uni_bss_bcnft(dev, info, true);
1937
1938		ieee80211_queue_delayed_work(hw, &dev->mlo_pm_work, 5 * HZ);
1939		mvif->mlo_pm_state = MT792x_MLO_CHANGED_PS;
1940	}
1941
1942	if (changed & IEEE80211_CHANCTX_CHANGE_PUNCTURING)
1943		mt7925_mcu_set_eht_pp(mvif->phy->mt76, &mconf->mt76,
1944				      link_conf, NULL);
1945
1946	if (changed & BSS_CHANGED_CQM)
1947		mt7925_mcu_set_rssimonitor(dev, vif);
1948
1949	mt792x_mutex_release(dev);
1950}
1951
1952static int
1953mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1954			u16 old_links, u16 new_links,
1955			struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS])
1956{
1957	struct mt792x_bss_conf *mconfs[IEEE80211_MLD_MAX_NUM_LINKS] = {}, *mconf;
1958	struct mt792x_link_sta *mlinks[IEEE80211_MLD_MAX_NUM_LINKS] = {}, *mlink;
1959	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1960	unsigned long add = new_links & ~old_links;
1961	unsigned long rem = old_links & ~new_links;
1962	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1963	struct mt792x_phy *phy = mt792x_hw_phy(hw);
1964	struct ieee80211_bss_conf *link_conf;
1965	unsigned int link_id;
1966	int err;
1967
1968	if (old_links == new_links)
1969		return 0;
1970
1971	mt792x_mutex_acquire(dev);
1972
1973	for_each_set_bit(link_id, &rem, IEEE80211_MLD_MAX_NUM_LINKS) {
1974		mconf = mt792x_vif_to_link(mvif, link_id);
1975		mlink = mt792x_sta_to_link(&mvif->sta, link_id);
1976
1977		if (!mconf || !mlink)
1978			continue;
1979
1980		if (mconf != &mvif->bss_conf) {
1981			mt792x_mac_link_bss_remove(dev, mconf, mlink);
1982			devm_kfree(dev->mt76.dev, mconf);
1983			devm_kfree(dev->mt76.dev, mlink);
1984		}
1985
1986		rcu_assign_pointer(mvif->link_conf[link_id], NULL);
1987		rcu_assign_pointer(mvif->sta.link[link_id], NULL);
1988	}
1989
1990	for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) {
1991		if (!old_links) {
1992			mvif->deflink_id = link_id;
1993			mconf = &mvif->bss_conf;
1994			mlink = &mvif->sta.deflink;
1995		} else {
1996			mconf = devm_kzalloc(dev->mt76.dev, sizeof(*mconf),
1997					     GFP_KERNEL);
1998			mlink = devm_kzalloc(dev->mt76.dev, sizeof(*mlink),
1999					     GFP_KERNEL);
2000			if (!mconf || !mlink) {
2001				mt792x_mutex_release(dev);
2002				return -ENOMEM;
2003			}
2004		}
2005
2006		mconfs[link_id] = mconf;
2007		mlinks[link_id] = mlink;
2008		mconf->link_id = link_id;
2009		mconf->vif = mvif;
2010		mlink->wcid.link_id = link_id;
2011		mlink->wcid.link_valid = !!vif->valid_links;
2012		mlink->wcid.def_wcid = &mvif->sta.deflink.wcid;
2013	}
2014
2015	if (hweight16(mvif->valid_links) == 0)
2016		mt792x_mac_link_bss_remove(dev, &mvif->bss_conf,
2017					   &mvif->sta.deflink);
2018
2019	for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) {
2020		mconf = mconfs[link_id];
2021		mlink = mlinks[link_id];
2022		link_conf = mt792x_vif_to_bss_conf(vif, link_id);
2023
2024		rcu_assign_pointer(mvif->link_conf[link_id], mconf);
2025		rcu_assign_pointer(mvif->sta.link[link_id], mlink);
2026
2027		err = mt7925_mac_link_bss_add(dev, link_conf, mlink);
2028		if (err < 0)
2029			goto free;
2030
2031		if (mconf != &mvif->bss_conf) {
2032			err = mt7925_set_mlo_roc(phy, &mvif->bss_conf,
2033						 vif->active_links);
2034			if (err < 0)
2035				goto free;
2036		}
2037	}
2038
2039	mvif->valid_links = new_links;
2040
2041	mt792x_mutex_release(dev);
2042
2043	return 0;
2044
2045free:
2046	for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) {
2047		rcu_assign_pointer(mvif->link_conf[link_id], NULL);
2048		rcu_assign_pointer(mvif->sta.link[link_id], NULL);
2049
2050		if (mconf != &mvif->bss_conf)
2051			devm_kfree(dev->mt76.dev, mconfs[link_id]);
2052		if (mlink != &mvif->sta.deflink)
2053			devm_kfree(dev->mt76.dev, mlinks[link_id]);
2054	}
2055
2056	mt792x_mutex_release(dev);
2057
2058	return err;
2059}
2060
2061static int
2062mt7925_change_sta_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2063			struct ieee80211_sta *sta, u16 old_links, u16 new_links)
2064{
2065	unsigned long add = new_links & ~old_links;
2066	unsigned long rem = old_links & ~new_links;
2067	struct mt792x_dev *dev = mt792x_hw_dev(hw);
2068	int err = 0;
2069
2070	if (old_links == new_links)
2071		return 0;
2072
2073	mt792x_mutex_acquire(dev);
2074
2075	err = mt7925_mac_sta_remove_links(dev, vif, sta, rem);
2076	if (err < 0)
2077		goto out;
2078
2079	err = mt7925_mac_sta_add_links(dev, vif, sta, add);
2080	if (err < 0)
2081		goto out;
2082
2083out:
2084	mt792x_mutex_release(dev);
2085
2086	return err;
2087}
2088
2089static int mt7925_assign_vif_chanctx(struct ieee80211_hw *hw,
2090				     struct ieee80211_vif *vif,
2091				     struct ieee80211_bss_conf *link_conf,
2092				     struct ieee80211_chanctx_conf *ctx)
2093{
2094	struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv;
2095	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
2096	struct mt792x_dev *dev = mt792x_hw_dev(hw);
2097	struct ieee80211_bss_conf *pri_link_conf;
2098	struct mt792x_bss_conf *mconf;
2099
2100	mutex_lock(&dev->mt76.mutex);
2101
2102	if (ieee80211_vif_is_mld(vif)) {
2103		mconf = mt792x_vif_to_link(mvif, link_conf->link_id);
2104		pri_link_conf = mt792x_vif_to_bss_conf(vif, mvif->deflink_id);
2105
2106		if (vif->type == NL80211_IFTYPE_STATION &&
2107		    mconf == &mvif->bss_conf)
2108			mt7925_mcu_add_bss_info(&dev->phy, NULL, pri_link_conf,
2109						NULL, true);
2110	} else {
2111		mconf = &mvif->bss_conf;
2112	}
2113
2114	mconf->mt76.ctx = ctx;
2115	mctx->bss_conf = mconf;
2116	mutex_unlock(&dev->mt76.mutex);
2117
2118	return 0;
2119}
2120
2121static void mt7925_unassign_vif_chanctx(struct ieee80211_hw *hw,
2122					struct ieee80211_vif *vif,
2123					struct ieee80211_bss_conf *link_conf,
2124					struct ieee80211_chanctx_conf *ctx)
2125{
2126	struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv;
2127	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
2128	struct mt792x_dev *dev = mt792x_hw_dev(hw);
2129	struct mt792x_bss_conf *mconf;
2130
2131	mutex_lock(&dev->mt76.mutex);
2132
2133	if (ieee80211_vif_is_mld(vif)) {
2134		mconf = mt792x_vif_to_link(mvif, link_conf->link_id);
2135
2136		if (vif->type == NL80211_IFTYPE_STATION &&
2137		    mconf == &mvif->bss_conf)
2138			mt7925_mcu_add_bss_info(&dev->phy, NULL, link_conf,
2139						NULL, false);
2140	} else {
2141		mconf = &mvif->bss_conf;
2142	}
2143
2144	mctx->bss_conf = NULL;
2145	mconf->mt76.ctx = NULL;
2146	mutex_unlock(&dev->mt76.mutex);
2147}
2148
2149static void mt7925_rfkill_poll(struct ieee80211_hw *hw)
2150{
2151	struct mt792x_phy *phy = mt792x_hw_phy(hw);
2152	int ret;
2153
2154	mt792x_mutex_acquire(phy->dev);
2155	ret = mt7925_mcu_wf_rf_pin_ctrl(phy);
2156	mt792x_mutex_release(phy->dev);
2157
2158	wiphy_rfkill_set_hw_state(hw->wiphy, ret == 0);
2159}
2160
2161const struct ieee80211_ops mt7925_ops = {
2162	.tx = mt792x_tx,
2163	.start = mt7925_start,
2164	.stop = mt792x_stop,
2165	.add_interface = mt7925_add_interface,
2166	.remove_interface = mt792x_remove_interface,
2167	.config = mt7925_config,
2168	.conf_tx = mt7925_conf_tx,
2169	.configure_filter = mt7925_configure_filter,
2170	.start_ap = mt7925_start_ap,
2171	.stop_ap = mt7925_stop_ap,
2172	.sta_state = mt76_sta_state,
2173	.sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
2174	.set_key = mt7925_set_key,
2175	.sta_set_decap_offload = mt7925_sta_set_decap_offload,
2176#if IS_ENABLED(CONFIG_IPV6)
2177	.ipv6_addr_change = mt7925_ipv6_addr_change,
2178#endif /* CONFIG_IPV6 */
2179	.ampdu_action = mt7925_ampdu_action,
2180	.set_rts_threshold = mt7925_set_rts_threshold,
2181	.wake_tx_queue = mt76_wake_tx_queue,
2182	.release_buffered_frames = mt76_release_buffered_frames,
2183	.channel_switch_beacon = mt7925_channel_switch_beacon,
2184	.get_txpower = mt76_get_txpower,
2185	.get_stats = mt792x_get_stats,
2186	.get_et_sset_count = mt792x_get_et_sset_count,
2187	.get_et_strings = mt792x_get_et_strings,
2188	.get_et_stats = mt792x_get_et_stats,
2189	.get_tsf = mt792x_get_tsf,
2190	.set_tsf = mt792x_set_tsf,
2191	.get_survey = mt76_get_survey,
2192	.get_antenna = mt76_get_antenna,
2193	.set_antenna = mt7925_set_antenna,
2194	.set_coverage_class = mt792x_set_coverage_class,
2195	.hw_scan = mt7925_hw_scan,
2196	.cancel_hw_scan = mt7925_cancel_hw_scan,
2197	.sta_statistics = mt792x_sta_statistics,
2198	.sched_scan_start = mt7925_start_sched_scan,
2199	.sched_scan_stop = mt7925_stop_sched_scan,
2200	CFG80211_TESTMODE_CMD(mt7925_testmode_cmd)
2201	CFG80211_TESTMODE_DUMP(mt7925_testmode_dump)
2202#ifdef CONFIG_PM
2203	.suspend = mt7925_suspend,
2204	.resume = mt7925_resume,
2205	.set_wakeup = mt792x_set_wakeup,
2206	.set_rekey_data = mt7925_set_rekey_data,
2207#endif /* CONFIG_PM */
2208	.flush = mt792x_flush,
2209	.set_sar_specs = mt7925_set_sar_specs,
2210	.remain_on_channel = mt7925_remain_on_channel,
2211	.cancel_remain_on_channel = mt7925_cancel_remain_on_channel,
2212	.add_chanctx = mt7925_add_chanctx,
2213	.remove_chanctx = mt7925_remove_chanctx,
2214	.change_chanctx = mt7925_change_chanctx,
2215	.assign_vif_chanctx = mt7925_assign_vif_chanctx,
2216	.unassign_vif_chanctx = mt7925_unassign_vif_chanctx,
2217	.mgd_prepare_tx = mt7925_mgd_prepare_tx,
2218	.mgd_complete_tx = mt7925_mgd_complete_tx,
2219	.vif_cfg_changed = mt7925_vif_cfg_changed,
2220	.link_info_changed = mt7925_link_info_changed,
2221	.change_vif_links = mt7925_change_vif_links,
2222	.change_sta_links = mt7925_change_sta_links,
2223	.rfkill_poll = mt7925_rfkill_poll,
2224};
2225EXPORT_SYMBOL_GPL(mt7925_ops);
2226
2227MODULE_AUTHOR("Deren Wu <deren.wu@mediatek.com>");
2228MODULE_DESCRIPTION("MediaTek MT7925 core driver");
2229MODULE_LICENSE("Dual BSD/GPL");
~/ Read-only file preview.