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