16c92544dSBjoern A. Zeeb // SPDX-License-Identifier: ISC
26c92544dSBjoern A. Zeeb /* Copyright (C) 2020 MediaTek Inc. */
36c92544dSBjoern A. Zeeb
46c92544dSBjoern A. Zeeb #include <linux/etherdevice.h>
56c92544dSBjoern A. Zeeb #include <linux/platform_device.h>
66c92544dSBjoern A. Zeeb #include <linux/pci.h>
76c92544dSBjoern A. Zeeb #include <linux/module.h>
86c92544dSBjoern A. Zeeb #include <net/ipv6.h>
96c92544dSBjoern A. Zeeb #include "mt7921.h"
106c92544dSBjoern A. Zeeb #include "mcu.h"
116c92544dSBjoern A. Zeeb
126c92544dSBjoern A. Zeeb static int
mt7921_init_he_caps(struct mt792x_phy * phy,enum nl80211_band band,struct ieee80211_sband_iftype_data * data)13cbb3ec25SBjoern A. Zeeb mt7921_init_he_caps(struct mt792x_phy *phy, enum nl80211_band band,
146c92544dSBjoern A. Zeeb struct ieee80211_sband_iftype_data *data)
156c92544dSBjoern A. Zeeb {
166c92544dSBjoern A. Zeeb int i, idx = 0;
176c92544dSBjoern A. Zeeb int nss = hweight8(phy->mt76->chainmask);
186c92544dSBjoern A. Zeeb u16 mcs_map = 0;
196c92544dSBjoern A. Zeeb
206c92544dSBjoern A. Zeeb for (i = 0; i < 8; i++) {
216c92544dSBjoern A. Zeeb if (i < nss)
226c92544dSBjoern A. Zeeb mcs_map |= (IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2));
236c92544dSBjoern A. Zeeb else
246c92544dSBjoern A. Zeeb mcs_map |= (IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
256c92544dSBjoern A. Zeeb }
266c92544dSBjoern A. Zeeb
276c92544dSBjoern A. Zeeb for (i = 0; i < NUM_NL80211_IFTYPES; i++) {
286c92544dSBjoern A. Zeeb struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap;
296c92544dSBjoern A. Zeeb struct ieee80211_he_cap_elem *he_cap_elem =
306c92544dSBjoern A. Zeeb &he_cap->he_cap_elem;
316c92544dSBjoern A. Zeeb struct ieee80211_he_mcs_nss_supp *he_mcs =
326c92544dSBjoern A. Zeeb &he_cap->he_mcs_nss_supp;
336c92544dSBjoern A. Zeeb
346c92544dSBjoern A. Zeeb switch (i) {
356c92544dSBjoern A. Zeeb case NL80211_IFTYPE_STATION:
366c92544dSBjoern A. Zeeb case NL80211_IFTYPE_AP:
376c92544dSBjoern A. Zeeb break;
386c92544dSBjoern A. Zeeb default:
396c92544dSBjoern A. Zeeb continue;
406c92544dSBjoern A. Zeeb }
416c92544dSBjoern A. Zeeb
426c92544dSBjoern A. Zeeb data[idx].types_mask = BIT(i);
436c92544dSBjoern A. Zeeb he_cap->has_he = true;
446c92544dSBjoern A. Zeeb
456c92544dSBjoern A. Zeeb he_cap_elem->mac_cap_info[0] =
466c92544dSBjoern A. Zeeb IEEE80211_HE_MAC_CAP0_HTC_HE;
476c92544dSBjoern A. Zeeb he_cap_elem->mac_cap_info[3] =
486c92544dSBjoern A. Zeeb IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
496c92544dSBjoern A. Zeeb IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3;
506c92544dSBjoern A. Zeeb he_cap_elem->mac_cap_info[4] =
516c92544dSBjoern A. Zeeb IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU;
526c92544dSBjoern A. Zeeb
536c92544dSBjoern A. Zeeb if (band == NL80211_BAND_2GHZ)
546c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[0] =
556c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
566c92544dSBjoern A. Zeeb else
576c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[0] =
586c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G;
596c92544dSBjoern A. Zeeb
606c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[1] =
616c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD;
626c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[2] =
636c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
646c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
656c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
666c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
676c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO;
686c92544dSBjoern A. Zeeb
696c92544dSBjoern A. Zeeb switch (i) {
706c92544dSBjoern A. Zeeb case NL80211_IFTYPE_AP:
716c92544dSBjoern A. Zeeb he_cap_elem->mac_cap_info[2] |=
726c92544dSBjoern A. Zeeb IEEE80211_HE_MAC_CAP2_BSR;
736c92544dSBjoern A. Zeeb he_cap_elem->mac_cap_info[4] |=
746c92544dSBjoern A. Zeeb IEEE80211_HE_MAC_CAP4_BQR;
756c92544dSBjoern A. Zeeb he_cap_elem->mac_cap_info[5] |=
766c92544dSBjoern A. Zeeb IEEE80211_HE_MAC_CAP5_OM_CTRL_UL_MU_DATA_DIS_RX;
776c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[3] |=
786c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK |
796c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK;
806c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[6] |=
816c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE |
826c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT;
836c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[9] |=
846c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
856c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU;
866c92544dSBjoern A. Zeeb break;
876c92544dSBjoern A. Zeeb case NL80211_IFTYPE_STATION:
886c92544dSBjoern A. Zeeb he_cap_elem->mac_cap_info[1] |=
896c92544dSBjoern A. Zeeb IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US;
906c92544dSBjoern A. Zeeb
916c92544dSBjoern A. Zeeb if (band == NL80211_BAND_2GHZ)
926c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[0] |=
936c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G;
946c92544dSBjoern A. Zeeb else
956c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[0] |=
966c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G;
976c92544dSBjoern A. Zeeb
986c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[1] |=
996c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
1006c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US;
1016c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[3] |=
1026c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK |
1036c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK;
1046c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[4] |=
1056c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE |
1066c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4;
1076c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[5] |=
1086c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP5_NG16_SU_FEEDBACK |
1096c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK;
1106c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[6] |=
1116c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_42_SU |
1126c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU |
1136c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB |
1146c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE |
1156c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT;
1166c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[7] |=
1176c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP |
1186c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI;
1196c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[8] |=
1206c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
1216c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_484;
1226c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[9] |=
1236c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM |
1246c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK |
1256c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
1266c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU |
1276c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB |
1286c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB;
1296c92544dSBjoern A. Zeeb
1306c92544dSBjoern A. Zeeb if (is_mt7922(phy->mt76->dev)) {
1316c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[0] |=
1326c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
1336c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[8] |=
1346c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU |
1356c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU;
1366c92544dSBjoern A. Zeeb }
1376c92544dSBjoern A. Zeeb break;
1386c92544dSBjoern A. Zeeb }
1396c92544dSBjoern A. Zeeb
1406c92544dSBjoern A. Zeeb he_mcs->rx_mcs_80 = cpu_to_le16(mcs_map);
1416c92544dSBjoern A. Zeeb he_mcs->tx_mcs_80 = cpu_to_le16(mcs_map);
1426c92544dSBjoern A. Zeeb if (is_mt7922(phy->mt76->dev)) {
1436c92544dSBjoern A. Zeeb he_mcs->rx_mcs_160 = cpu_to_le16(mcs_map);
1446c92544dSBjoern A. Zeeb he_mcs->tx_mcs_160 = cpu_to_le16(mcs_map);
1456c92544dSBjoern A. Zeeb }
1466c92544dSBjoern A. Zeeb
1476c92544dSBjoern A. Zeeb memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres));
1486c92544dSBjoern A. Zeeb if (he_cap_elem->phy_cap_info[6] &
1496c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
150*8ba4d145SBjoern A. Zeeb mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss, band);
1516c92544dSBjoern A. Zeeb } else {
1526c92544dSBjoern A. Zeeb he_cap_elem->phy_cap_info[9] |=
1536c92544dSBjoern A. Zeeb u8_encode_bits(IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US,
1546c92544dSBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK);
1556c92544dSBjoern A. Zeeb }
1566c92544dSBjoern A. Zeeb
1576c92544dSBjoern A. Zeeb if (band == NL80211_BAND_6GHZ) {
1586c92544dSBjoern A. Zeeb struct ieee80211_supported_band *sband =
1596c92544dSBjoern A. Zeeb &phy->mt76->sband_5g.sband;
1606c92544dSBjoern A. Zeeb struct ieee80211_sta_vht_cap *vht_cap = &sband->vht_cap;
1616c92544dSBjoern A. Zeeb struct ieee80211_sta_ht_cap *ht_cap = &sband->ht_cap;
1626c92544dSBjoern A. Zeeb u32 exp;
1636c92544dSBjoern A. Zeeb u16 cap;
1646c92544dSBjoern A. Zeeb
1656c92544dSBjoern A. Zeeb cap = u16_encode_bits(ht_cap->ampdu_density,
1666c92544dSBjoern A. Zeeb IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START);
1676c92544dSBjoern A. Zeeb exp = u32_get_bits(vht_cap->cap,
1686c92544dSBjoern A. Zeeb IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK);
1696c92544dSBjoern A. Zeeb cap |= u16_encode_bits(exp,
1706c92544dSBjoern A. Zeeb IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP);
1716c92544dSBjoern A. Zeeb exp = u32_get_bits(vht_cap->cap,
1726c92544dSBjoern A. Zeeb IEEE80211_VHT_CAP_MAX_MPDU_MASK);
1736c92544dSBjoern A. Zeeb cap |= u16_encode_bits(exp,
1746c92544dSBjoern A. Zeeb IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN);
1756c92544dSBjoern A. Zeeb if (vht_cap->cap & IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN)
1766c92544dSBjoern A. Zeeb cap |= IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS;
1776c92544dSBjoern A. Zeeb if (vht_cap->cap & IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN)
1786c92544dSBjoern A. Zeeb cap |= IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS;
1796c92544dSBjoern A. Zeeb
1806c92544dSBjoern A. Zeeb data[idx].he_6ghz_capa.capa = cpu_to_le16(cap);
1816c92544dSBjoern A. Zeeb }
1826c92544dSBjoern A. Zeeb idx++;
1836c92544dSBjoern A. Zeeb }
1846c92544dSBjoern A. Zeeb
1856c92544dSBjoern A. Zeeb return idx;
1866c92544dSBjoern A. Zeeb }
1876c92544dSBjoern A. Zeeb
mt7921_set_stream_he_caps(struct mt792x_phy * phy)188cbb3ec25SBjoern A. Zeeb void mt7921_set_stream_he_caps(struct mt792x_phy *phy)
1896c92544dSBjoern A. Zeeb {
1906c92544dSBjoern A. Zeeb struct ieee80211_sband_iftype_data *data;
1916c92544dSBjoern A. Zeeb struct ieee80211_supported_band *band;
1926c92544dSBjoern A. Zeeb int n;
1936c92544dSBjoern A. Zeeb
1946c92544dSBjoern A. Zeeb if (phy->mt76->cap.has_2ghz) {
1956c92544dSBjoern A. Zeeb data = phy->iftype[NL80211_BAND_2GHZ];
1966c92544dSBjoern A. Zeeb n = mt7921_init_he_caps(phy, NL80211_BAND_2GHZ, data);
1976c92544dSBjoern A. Zeeb
1986c92544dSBjoern A. Zeeb band = &phy->mt76->sband_2g.sband;
199*8ba4d145SBjoern A. Zeeb _ieee80211_set_sband_iftype_data(band, data, n);
2006c92544dSBjoern A. Zeeb }
2016c92544dSBjoern A. Zeeb
2026c92544dSBjoern A. Zeeb if (phy->mt76->cap.has_5ghz) {
2036c92544dSBjoern A. Zeeb data = phy->iftype[NL80211_BAND_5GHZ];
2046c92544dSBjoern A. Zeeb n = mt7921_init_he_caps(phy, NL80211_BAND_5GHZ, data);
2056c92544dSBjoern A. Zeeb
2066c92544dSBjoern A. Zeeb band = &phy->mt76->sband_5g.sband;
207*8ba4d145SBjoern A. Zeeb _ieee80211_set_sband_iftype_data(band, data, n);
2086c92544dSBjoern A. Zeeb
2096c92544dSBjoern A. Zeeb if (phy->mt76->cap.has_6ghz) {
2106c92544dSBjoern A. Zeeb data = phy->iftype[NL80211_BAND_6GHZ];
2116c92544dSBjoern A. Zeeb n = mt7921_init_he_caps(phy, NL80211_BAND_6GHZ, data);
2126c92544dSBjoern A. Zeeb
2136c92544dSBjoern A. Zeeb band = &phy->mt76->sband_6g.sband;
214*8ba4d145SBjoern A. Zeeb _ieee80211_set_sband_iftype_data(band, data, n);
2156c92544dSBjoern A. Zeeb }
2166c92544dSBjoern A. Zeeb }
2176c92544dSBjoern A. Zeeb }
2186c92544dSBjoern A. Zeeb
__mt7921_start(struct mt792x_phy * phy)219cbb3ec25SBjoern A. Zeeb int __mt7921_start(struct mt792x_phy *phy)
2206c92544dSBjoern A. Zeeb {
2216c92544dSBjoern A. Zeeb struct mt76_phy *mphy = phy->mt76;
2226c92544dSBjoern A. Zeeb int err;
2236c92544dSBjoern A. Zeeb
2246c92544dSBjoern A. Zeeb err = mt76_connac_mcu_set_mac_enable(mphy->dev, 0, true, false);
2256c92544dSBjoern A. Zeeb if (err)
2266c92544dSBjoern A. Zeeb return err;
2276c92544dSBjoern A. Zeeb
2286c92544dSBjoern A. Zeeb err = mt76_connac_mcu_set_channel_domain(mphy);
2296c92544dSBjoern A. Zeeb if (err)
2306c92544dSBjoern A. Zeeb return err;
2316c92544dSBjoern A. Zeeb
2326c92544dSBjoern A. Zeeb err = mt7921_mcu_set_chan_info(phy, MCU_EXT_CMD(SET_RX_PATH));
2336c92544dSBjoern A. Zeeb if (err)
2346c92544dSBjoern A. Zeeb return err;
2356c92544dSBjoern A. Zeeb
2366c92544dSBjoern A. Zeeb err = mt7921_set_tx_sar_pwr(mphy->hw, NULL);
2376c92544dSBjoern A. Zeeb if (err)
2386c92544dSBjoern A. Zeeb return err;
2396c92544dSBjoern A. Zeeb
240cbb3ec25SBjoern A. Zeeb mt792x_mac_reset_counters(phy);
2416c92544dSBjoern A. Zeeb set_bit(MT76_STATE_RUNNING, &mphy->state);
2426c92544dSBjoern A. Zeeb
2436c92544dSBjoern A. Zeeb ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
244cbb3ec25SBjoern A. Zeeb MT792x_WATCHDOG_TIME);
245*8ba4d145SBjoern A. Zeeb if (mt76_is_mmio(mphy->dev)) {
246*8ba4d145SBjoern A. Zeeb err = mt7921_mcu_radio_led_ctrl(phy->dev, EXT_CMD_RADIO_LED_CTRL_ENABLE);
247*8ba4d145SBjoern A. Zeeb if (err)
248*8ba4d145SBjoern A. Zeeb return err;
249*8ba4d145SBjoern A. Zeeb
250*8ba4d145SBjoern A. Zeeb err = mt7921_mcu_radio_led_ctrl(phy->dev, EXT_CMD_RADIO_ON_LED);
251*8ba4d145SBjoern A. Zeeb if (err)
252*8ba4d145SBjoern A. Zeeb return err;
253*8ba4d145SBjoern A. Zeeb }
254*8ba4d145SBjoern A. Zeeb
255*8ba4d145SBjoern A. Zeeb if (phy->chip_cap & MT792x_CHIP_CAP_WF_RF_PIN_CTRL_EVT_EN) {
256*8ba4d145SBjoern A. Zeeb mt7921_mcu_wf_rf_pin_ctrl(phy, WF_RF_PIN_INIT);
257*8ba4d145SBjoern A. Zeeb wiphy_rfkill_start_polling(mphy->hw->wiphy);
258*8ba4d145SBjoern A. Zeeb }
2596c92544dSBjoern A. Zeeb
2606c92544dSBjoern A. Zeeb return 0;
2616c92544dSBjoern A. Zeeb }
2626c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(__mt7921_start);
2636c92544dSBjoern A. Zeeb
mt7921_start(struct ieee80211_hw * hw)2646c92544dSBjoern A. Zeeb static int mt7921_start(struct ieee80211_hw *hw)
2656c92544dSBjoern A. Zeeb {
266cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
2676c92544dSBjoern A. Zeeb int err;
2686c92544dSBjoern A. Zeeb
269cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(phy->dev);
2706c92544dSBjoern A. Zeeb err = __mt7921_start(phy);
271cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(phy->dev);
2726c92544dSBjoern A. Zeeb
2736c92544dSBjoern A. Zeeb return err;
2746c92544dSBjoern A. Zeeb }
2756c92544dSBjoern A. Zeeb
mt7921_stop(struct ieee80211_hw * hw,bool suspend)276*8ba4d145SBjoern A. Zeeb static void mt7921_stop(struct ieee80211_hw *hw, bool suspend)
2776c92544dSBjoern A. Zeeb {
278cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
279*8ba4d145SBjoern A. Zeeb int err = 0;
2806c92544dSBjoern A. Zeeb
281*8ba4d145SBjoern A. Zeeb if (mt76_is_mmio(&dev->mt76)) {
282cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
283*8ba4d145SBjoern A. Zeeb err = mt7921_mcu_radio_led_ctrl(dev, EXT_CMD_RADIO_OFF_LED);
284cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
285*8ba4d145SBjoern A. Zeeb if (err)
286*8ba4d145SBjoern A. Zeeb return;
2876c92544dSBjoern A. Zeeb }
288*8ba4d145SBjoern A. Zeeb
289*8ba4d145SBjoern A. Zeeb mt792x_stop(hw, false);
290*8ba4d145SBjoern A. Zeeb }
2916c92544dSBjoern A. Zeeb
292cbb3ec25SBjoern A. Zeeb static int
mt7921_add_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)293cbb3ec25SBjoern A. Zeeb mt7921_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2946c92544dSBjoern A. Zeeb {
295cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
296cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
297cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
2986c92544dSBjoern A. Zeeb struct mt76_txq *mtxq;
2996c92544dSBjoern A. Zeeb int idx, ret = 0;
3006c92544dSBjoern A. Zeeb
301cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
3026c92544dSBjoern A. Zeeb
303*8ba4d145SBjoern A. Zeeb mvif->bss_conf.mt76.idx = __ffs64(~dev->mt76.vif_mask);
304*8ba4d145SBjoern A. Zeeb if (mvif->bss_conf.mt76.idx >= MT792x_MAX_INTERFACES) {
3056c92544dSBjoern A. Zeeb ret = -ENOSPC;
3066c92544dSBjoern A. Zeeb goto out;
3076c92544dSBjoern A. Zeeb }
3086c92544dSBjoern A. Zeeb
309*8ba4d145SBjoern A. Zeeb mvif->bss_conf.mt76.omac_idx = mvif->bss_conf.mt76.idx;
3106c92544dSBjoern A. Zeeb mvif->phy = phy;
311*8ba4d145SBjoern A. Zeeb mvif->bss_conf.vif = mvif;
312*8ba4d145SBjoern A. Zeeb mvif->bss_conf.mt76.band_idx = 0;
313*8ba4d145SBjoern A. Zeeb mvif->bss_conf.mt76.wmm_idx = mvif->bss_conf.mt76.idx % MT76_CONNAC_MAX_WMM_SETS;
3146c92544dSBjoern A. Zeeb
315*8ba4d145SBjoern A. Zeeb ret = mt76_connac_mcu_uni_add_dev(&dev->mphy, &vif->bss_conf,
316*8ba4d145SBjoern A. Zeeb &mvif->bss_conf.mt76,
317*8ba4d145SBjoern A. Zeeb &mvif->sta.deflink.wcid, true);
3186c92544dSBjoern A. Zeeb if (ret)
3196c92544dSBjoern A. Zeeb goto out;
3206c92544dSBjoern A. Zeeb
321*8ba4d145SBjoern A. Zeeb dev->mt76.vif_mask |= BIT_ULL(mvif->bss_conf.mt76.idx);
322*8ba4d145SBjoern A. Zeeb phy->omac_mask |= BIT_ULL(mvif->bss_conf.mt76.omac_idx);
3236c92544dSBjoern A. Zeeb
324*8ba4d145SBjoern A. Zeeb idx = MT792x_WTBL_RESERVED - mvif->bss_conf.mt76.idx;
3256c92544dSBjoern A. Zeeb
326*8ba4d145SBjoern A. Zeeb INIT_LIST_HEAD(&mvif->sta.deflink.wcid.poll_list);
327*8ba4d145SBjoern A. Zeeb mvif->sta.deflink.wcid.idx = idx;
328*8ba4d145SBjoern A. Zeeb mvif->sta.deflink.wcid.tx_info |= MT_WCID_TX_INFO_SET;
329*8ba4d145SBjoern A. Zeeb mt76_wcid_init(&mvif->sta.deflink.wcid, mvif->bss_conf.mt76.band_idx);
3306c92544dSBjoern A. Zeeb
3316c92544dSBjoern A. Zeeb mt7921_mac_wtbl_update(dev, idx,
3326c92544dSBjoern A. Zeeb MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
3336c92544dSBjoern A. Zeeb
334*8ba4d145SBjoern A. Zeeb ewma_rssi_init(&mvif->bss_conf.rssi);
3356c92544dSBjoern A. Zeeb
336*8ba4d145SBjoern A. Zeeb rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.deflink.wcid);
3376c92544dSBjoern A. Zeeb if (vif->txq) {
3386c92544dSBjoern A. Zeeb mtxq = (struct mt76_txq *)vif->txq->drv_priv;
3396c92544dSBjoern A. Zeeb mtxq->wcid = idx;
3406c92544dSBjoern A. Zeeb }
3416c92544dSBjoern A. Zeeb
3426c92544dSBjoern A. Zeeb vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
343*8ba4d145SBjoern A. Zeeb if (phy->chip_cap & MT792x_CHIP_CAP_RSSI_NOTIFY_EVT_EN)
344*8ba4d145SBjoern A. Zeeb vif->driver_flags |= IEEE80211_VIF_SUPPORTS_CQM_RSSI;
345*8ba4d145SBjoern A. Zeeb
346*8ba4d145SBjoern A. Zeeb INIT_WORK(&mvif->csa_work, mt7921_csa_work);
347*8ba4d145SBjoern A. Zeeb timer_setup(&mvif->csa_timer, mt792x_csa_timer, 0);
3486c92544dSBjoern A. Zeeb out:
349cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
3506c92544dSBjoern A. Zeeb
3516c92544dSBjoern A. Zeeb return ret;
3526c92544dSBjoern A. Zeeb }
3536c92544dSBjoern A. Zeeb
mt7921_roc_iter(void * priv,u8 * mac,struct ieee80211_vif * vif)354cbb3ec25SBjoern A. Zeeb static void mt7921_roc_iter(void *priv, u8 *mac,
3556c92544dSBjoern A. Zeeb struct ieee80211_vif *vif)
3566c92544dSBjoern A. Zeeb {
357cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
358cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = priv;
3596c92544dSBjoern A. Zeeb
360cbb3ec25SBjoern A. Zeeb mt7921_mcu_abort_roc(phy, mvif, phy->roc_token_id);
3616c92544dSBjoern A. Zeeb }
3626c92544dSBjoern A. Zeeb
mt7921_roc_abort_sync(struct mt792x_dev * dev)363*8ba4d145SBjoern A. Zeeb void mt7921_roc_abort_sync(struct mt792x_dev *dev)
364*8ba4d145SBjoern A. Zeeb {
365*8ba4d145SBjoern A. Zeeb struct mt792x_phy *phy = &dev->phy;
366*8ba4d145SBjoern A. Zeeb
367*8ba4d145SBjoern A. Zeeb del_timer_sync(&phy->roc_timer);
368*8ba4d145SBjoern A. Zeeb cancel_work_sync(&phy->roc_work);
369*8ba4d145SBjoern A. Zeeb if (test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
370*8ba4d145SBjoern A. Zeeb ieee80211_iterate_interfaces(mt76_hw(dev),
371*8ba4d145SBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL,
372*8ba4d145SBjoern A. Zeeb mt7921_roc_iter, (void *)phy);
373*8ba4d145SBjoern A. Zeeb }
374*8ba4d145SBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt7921_roc_abort_sync);
375*8ba4d145SBjoern A. Zeeb
mt7921_roc_work(struct work_struct * work)376cbb3ec25SBjoern A. Zeeb void mt7921_roc_work(struct work_struct *work)
3776c92544dSBjoern A. Zeeb {
378cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy;
379cbb3ec25SBjoern A. Zeeb
380cbb3ec25SBjoern A. Zeeb phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy,
381cbb3ec25SBjoern A. Zeeb roc_work);
382cbb3ec25SBjoern A. Zeeb
383cbb3ec25SBjoern A. Zeeb if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
384cbb3ec25SBjoern A. Zeeb return;
385cbb3ec25SBjoern A. Zeeb
386cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(phy->dev);
387cbb3ec25SBjoern A. Zeeb ieee80211_iterate_active_interfaces(phy->mt76->hw,
388cbb3ec25SBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL,
389cbb3ec25SBjoern A. Zeeb mt7921_roc_iter, phy);
390cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(phy->dev);
391cbb3ec25SBjoern A. Zeeb ieee80211_remain_on_channel_expired(phy->mt76->hw);
392cbb3ec25SBjoern A. Zeeb }
393cbb3ec25SBjoern A. Zeeb
mt7921_abort_roc(struct mt792x_phy * phy,struct mt792x_vif * vif)394cbb3ec25SBjoern A. Zeeb static int mt7921_abort_roc(struct mt792x_phy *phy, struct mt792x_vif *vif)
395cbb3ec25SBjoern A. Zeeb {
396cbb3ec25SBjoern A. Zeeb int err = 0;
397cbb3ec25SBjoern A. Zeeb
398cbb3ec25SBjoern A. Zeeb del_timer_sync(&phy->roc_timer);
399cbb3ec25SBjoern A. Zeeb cancel_work_sync(&phy->roc_work);
400cbb3ec25SBjoern A. Zeeb
401cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(phy->dev);
402cbb3ec25SBjoern A. Zeeb if (test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
403cbb3ec25SBjoern A. Zeeb err = mt7921_mcu_abort_roc(phy, vif, phy->roc_token_id);
404cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(phy->dev);
405cbb3ec25SBjoern A. Zeeb
406cbb3ec25SBjoern A. Zeeb return err;
407cbb3ec25SBjoern A. Zeeb }
408cbb3ec25SBjoern A. Zeeb
mt7921_set_roc(struct mt792x_phy * phy,struct mt792x_vif * vif,struct ieee80211_channel * chan,int duration,enum mt7921_roc_req type)409cbb3ec25SBjoern A. Zeeb static int mt7921_set_roc(struct mt792x_phy *phy,
410cbb3ec25SBjoern A. Zeeb struct mt792x_vif *vif,
411cbb3ec25SBjoern A. Zeeb struct ieee80211_channel *chan,
412cbb3ec25SBjoern A. Zeeb int duration,
413cbb3ec25SBjoern A. Zeeb enum mt7921_roc_req type)
414cbb3ec25SBjoern A. Zeeb {
415cbb3ec25SBjoern A. Zeeb int err;
416cbb3ec25SBjoern A. Zeeb
417cbb3ec25SBjoern A. Zeeb if (test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state))
418cbb3ec25SBjoern A. Zeeb return -EBUSY;
419cbb3ec25SBjoern A. Zeeb
420cbb3ec25SBjoern A. Zeeb phy->roc_grant = false;
421cbb3ec25SBjoern A. Zeeb
422cbb3ec25SBjoern A. Zeeb err = mt7921_mcu_set_roc(phy, vif, chan, duration, type,
423cbb3ec25SBjoern A. Zeeb ++phy->roc_token_id);
424cbb3ec25SBjoern A. Zeeb if (err < 0) {
425cbb3ec25SBjoern A. Zeeb clear_bit(MT76_STATE_ROC, &phy->mt76->state);
426cbb3ec25SBjoern A. Zeeb goto out;
427cbb3ec25SBjoern A. Zeeb }
428cbb3ec25SBjoern A. Zeeb
429cbb3ec25SBjoern A. Zeeb if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, HZ)) {
430cbb3ec25SBjoern A. Zeeb mt7921_mcu_abort_roc(phy, vif, phy->roc_token_id);
431cbb3ec25SBjoern A. Zeeb clear_bit(MT76_STATE_ROC, &phy->mt76->state);
432cbb3ec25SBjoern A. Zeeb err = -ETIMEDOUT;
433cbb3ec25SBjoern A. Zeeb }
434cbb3ec25SBjoern A. Zeeb
435cbb3ec25SBjoern A. Zeeb out:
436cbb3ec25SBjoern A. Zeeb return err;
437cbb3ec25SBjoern A. Zeeb }
438cbb3ec25SBjoern A. Zeeb
mt7921_remain_on_channel(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_channel * chan,int duration,enum ieee80211_roc_type type)439cbb3ec25SBjoern A. Zeeb static int mt7921_remain_on_channel(struct ieee80211_hw *hw,
440cbb3ec25SBjoern A. Zeeb struct ieee80211_vif *vif,
441cbb3ec25SBjoern A. Zeeb struct ieee80211_channel *chan,
442cbb3ec25SBjoern A. Zeeb int duration,
443cbb3ec25SBjoern A. Zeeb enum ieee80211_roc_type type)
444cbb3ec25SBjoern A. Zeeb {
445cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
446cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
447cbb3ec25SBjoern A. Zeeb int err;
448cbb3ec25SBjoern A. Zeeb
449cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(phy->dev);
450cbb3ec25SBjoern A. Zeeb err = mt7921_set_roc(phy, mvif, chan, duration, MT7921_ROC_REQ_ROC);
451cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(phy->dev);
452cbb3ec25SBjoern A. Zeeb
453cbb3ec25SBjoern A. Zeeb return err;
454cbb3ec25SBjoern A. Zeeb }
455cbb3ec25SBjoern A. Zeeb
mt7921_cancel_remain_on_channel(struct ieee80211_hw * hw,struct ieee80211_vif * vif)456cbb3ec25SBjoern A. Zeeb static int mt7921_cancel_remain_on_channel(struct ieee80211_hw *hw,
457cbb3ec25SBjoern A. Zeeb struct ieee80211_vif *vif)
458cbb3ec25SBjoern A. Zeeb {
459cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
460cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
461cbb3ec25SBjoern A. Zeeb
462cbb3ec25SBjoern A. Zeeb return mt7921_abort_roc(phy, mvif);
463cbb3ec25SBjoern A. Zeeb }
464cbb3ec25SBjoern A. Zeeb
mt7921_set_channel(struct mt76_phy * mphy)465*8ba4d145SBjoern A. Zeeb int mt7921_set_channel(struct mt76_phy *mphy)
466cbb3ec25SBjoern A. Zeeb {
467*8ba4d145SBjoern A. Zeeb struct mt792x_phy *phy = mphy->priv;
468cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = phy->dev;
4696c92544dSBjoern A. Zeeb int ret;
4706c92544dSBjoern A. Zeeb
471*8ba4d145SBjoern A. Zeeb mt76_connac_pm_wake(mphy, &dev->pm);
4726c92544dSBjoern A. Zeeb ret = mt7921_mcu_set_chan_info(phy, MCU_EXT_CMD(CHANNEL_SWITCH));
4736c92544dSBjoern A. Zeeb if (ret)
4746c92544dSBjoern A. Zeeb goto out;
4756c92544dSBjoern A. Zeeb
476cbb3ec25SBjoern A. Zeeb mt792x_mac_set_timeing(phy);
477cbb3ec25SBjoern A. Zeeb mt792x_mac_reset_counters(phy);
4786c92544dSBjoern A. Zeeb phy->noise = 0;
4796c92544dSBjoern A. Zeeb
4806c92544dSBjoern A. Zeeb out:
481*8ba4d145SBjoern A. Zeeb mt76_connac_power_save_sched(mphy, &dev->pm);
4826c92544dSBjoern A. Zeeb
483*8ba4d145SBjoern A. Zeeb ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
484cbb3ec25SBjoern A. Zeeb MT792x_WATCHDOG_TIME);
4856c92544dSBjoern A. Zeeb
4866c92544dSBjoern A. Zeeb return ret;
4876c92544dSBjoern A. Zeeb }
488*8ba4d145SBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt7921_set_channel);
4896c92544dSBjoern A. Zeeb
mt7921_set_key(struct ieee80211_hw * hw,enum set_key_cmd cmd,struct ieee80211_vif * vif,struct ieee80211_sta * sta,struct ieee80211_key_conf * key)4906c92544dSBjoern A. Zeeb static int mt7921_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4916c92544dSBjoern A. Zeeb struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4926c92544dSBjoern A. Zeeb struct ieee80211_key_conf *key)
4936c92544dSBjoern A. Zeeb {
494cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
495cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
496cbb3ec25SBjoern A. Zeeb struct mt792x_sta *msta = sta ? (struct mt792x_sta *)sta->drv_priv :
4976c92544dSBjoern A. Zeeb &mvif->sta;
498*8ba4d145SBjoern A. Zeeb struct mt76_wcid *wcid = &msta->deflink.wcid;
4996c92544dSBjoern A. Zeeb u8 *wcid_keyidx = &wcid->hw_key_idx;
5006c92544dSBjoern A. Zeeb int idx = key->keyidx, err = 0;
5016c92544dSBjoern A. Zeeb
5026c92544dSBjoern A. Zeeb /* The hardware does not support per-STA RX GTK, fallback
5036c92544dSBjoern A. Zeeb * to software mode for these.
5046c92544dSBjoern A. Zeeb */
5056c92544dSBjoern A. Zeeb if ((vif->type == NL80211_IFTYPE_ADHOC ||
5066c92544dSBjoern A. Zeeb vif->type == NL80211_IFTYPE_MESH_POINT) &&
5076c92544dSBjoern A. Zeeb (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
5086c92544dSBjoern A. Zeeb key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
5096c92544dSBjoern A. Zeeb !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
5106c92544dSBjoern A. Zeeb return -EOPNOTSUPP;
5116c92544dSBjoern A. Zeeb
5126c92544dSBjoern A. Zeeb /* fall back to sw encryption for unsupported ciphers */
5136c92544dSBjoern A. Zeeb switch (key->cipher) {
5146c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC:
5156c92544dSBjoern A. Zeeb key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
5166c92544dSBjoern A. Zeeb wcid_keyidx = &wcid->hw_key_idx2;
5176c92544dSBjoern A. Zeeb break;
5186c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40:
5196c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104:
5206c92544dSBjoern A. Zeeb if (!mvif->wep_sta)
5216c92544dSBjoern A. Zeeb return -EOPNOTSUPP;
5226c92544dSBjoern A. Zeeb break;
5236c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP:
5246c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP:
5256c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256:
5266c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP:
5276c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256:
5286c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_SMS4:
5296c92544dSBjoern A. Zeeb break;
5306c92544dSBjoern A. Zeeb default:
5316c92544dSBjoern A. Zeeb return -EOPNOTSUPP;
5326c92544dSBjoern A. Zeeb }
5336c92544dSBjoern A. Zeeb
534cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
5356c92544dSBjoern A. Zeeb
536cbb3ec25SBjoern A. Zeeb if (cmd == SET_KEY) {
5376c92544dSBjoern A. Zeeb *wcid_keyidx = idx;
538cbb3ec25SBjoern A. Zeeb } else {
539cbb3ec25SBjoern A. Zeeb if (idx == *wcid_keyidx)
5406c92544dSBjoern A. Zeeb *wcid_keyidx = -1;
541*8ba4d145SBjoern A. Zeeb
542*8ba4d145SBjoern A. Zeeb /* For security issue we don't trigger the key deletion when
543*8ba4d145SBjoern A. Zeeb * reassociating. But we should trigger the deletion process
544*8ba4d145SBjoern A. Zeeb * to avoid using incorrect cipher after disconnection,
545*8ba4d145SBjoern A. Zeeb */
546*8ba4d145SBjoern A. Zeeb if (vif->type != NL80211_IFTYPE_STATION || vif->cfg.assoc)
5476c92544dSBjoern A. Zeeb goto out;
548cbb3ec25SBjoern A. Zeeb }
5496c92544dSBjoern A. Zeeb
550cbb3ec25SBjoern A. Zeeb mt76_wcid_key_setup(&dev->mt76, wcid, key);
551*8ba4d145SBjoern A. Zeeb err = mt76_connac_mcu_add_key(&dev->mt76, vif, &msta->deflink.bip,
5526c92544dSBjoern A. Zeeb key, MCU_UNI_CMD(STA_REC_UPDATE),
553*8ba4d145SBjoern A. Zeeb &msta->deflink.wcid, cmd);
5546c92544dSBjoern A. Zeeb if (err)
5556c92544dSBjoern A. Zeeb goto out;
5566c92544dSBjoern A. Zeeb
5576c92544dSBjoern A. Zeeb if (key->cipher == WLAN_CIPHER_SUITE_WEP104 ||
5586c92544dSBjoern A. Zeeb key->cipher == WLAN_CIPHER_SUITE_WEP40)
5596c92544dSBjoern A. Zeeb err = mt76_connac_mcu_add_key(&dev->mt76, vif,
560*8ba4d145SBjoern A. Zeeb &mvif->wep_sta->deflink.bip,
5616c92544dSBjoern A. Zeeb key, MCU_UNI_CMD(STA_REC_UPDATE),
562*8ba4d145SBjoern A. Zeeb &mvif->wep_sta->deflink.wcid, cmd);
5636c92544dSBjoern A. Zeeb out:
564cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
5656c92544dSBjoern A. Zeeb
5666c92544dSBjoern A. Zeeb return err;
5676c92544dSBjoern A. Zeeb }
5686c92544dSBjoern A. Zeeb
5696c92544dSBjoern A. Zeeb static void
mt7921_pm_interface_iter(void * priv,u8 * mac,struct ieee80211_vif * vif)5706c92544dSBjoern A. Zeeb mt7921_pm_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
5716c92544dSBjoern A. Zeeb {
572cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = priv;
5736c92544dSBjoern A. Zeeb struct ieee80211_hw *hw = mt76_hw(dev);
5746c92544dSBjoern A. Zeeb bool pm_enable = dev->pm.enable;
5756c92544dSBjoern A. Zeeb int err;
5766c92544dSBjoern A. Zeeb
5776c92544dSBjoern A. Zeeb err = mt7921_mcu_set_beacon_filter(dev, vif, pm_enable);
5786c92544dSBjoern A. Zeeb if (err < 0)
5796c92544dSBjoern A. Zeeb return;
5806c92544dSBjoern A. Zeeb
5816c92544dSBjoern A. Zeeb if (pm_enable) {
5826c92544dSBjoern A. Zeeb vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
5836c92544dSBjoern A. Zeeb ieee80211_hw_set(hw, CONNECTION_MONITOR);
5846c92544dSBjoern A. Zeeb } else {
5856c92544dSBjoern A. Zeeb vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER;
5866c92544dSBjoern A. Zeeb __clear_bit(IEEE80211_HW_CONNECTION_MONITOR, hw->flags);
5876c92544dSBjoern A. Zeeb }
5886c92544dSBjoern A. Zeeb }
5896c92544dSBjoern A. Zeeb
5906c92544dSBjoern A. Zeeb static void
mt7921_sniffer_interface_iter(void * priv,u8 * mac,struct ieee80211_vif * vif)5916c92544dSBjoern A. Zeeb mt7921_sniffer_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
5926c92544dSBjoern A. Zeeb {
593cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = priv;
5946c92544dSBjoern A. Zeeb struct ieee80211_hw *hw = mt76_hw(dev);
5956c92544dSBjoern A. Zeeb struct mt76_connac_pm *pm = &dev->pm;
5966c92544dSBjoern A. Zeeb bool monitor = !!(hw->conf.flags & IEEE80211_CONF_MONITOR);
5976c92544dSBjoern A. Zeeb
5986c92544dSBjoern A. Zeeb mt7921_mcu_set_sniffer(dev, vif, monitor);
5996c92544dSBjoern A. Zeeb pm->enable = pm->enable_user && !monitor;
6006c92544dSBjoern A. Zeeb pm->ds_enable = pm->ds_enable_user && !monitor;
6016c92544dSBjoern A. Zeeb
6026c92544dSBjoern A. Zeeb mt76_connac_mcu_set_deep_sleep(&dev->mt76, pm->ds_enable);
6036c92544dSBjoern A. Zeeb
6046c92544dSBjoern A. Zeeb if (monitor)
6056c92544dSBjoern A. Zeeb mt7921_mcu_set_beacon_filter(dev, vif, false);
6066c92544dSBjoern A. Zeeb }
6076c92544dSBjoern A. Zeeb
mt7921_set_runtime_pm(struct mt792x_dev * dev)608cbb3ec25SBjoern A. Zeeb void mt7921_set_runtime_pm(struct mt792x_dev *dev)
6096c92544dSBjoern A. Zeeb {
6106c92544dSBjoern A. Zeeb struct ieee80211_hw *hw = mt76_hw(dev);
6116c92544dSBjoern A. Zeeb struct mt76_connac_pm *pm = &dev->pm;
6126c92544dSBjoern A. Zeeb bool monitor = !!(hw->conf.flags & IEEE80211_CONF_MONITOR);
6136c92544dSBjoern A. Zeeb
6146c92544dSBjoern A. Zeeb pm->enable = pm->enable_user && !monitor;
6156c92544dSBjoern A. Zeeb ieee80211_iterate_active_interfaces(hw,
6166c92544dSBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL,
6176c92544dSBjoern A. Zeeb mt7921_pm_interface_iter, dev);
6186c92544dSBjoern A. Zeeb pm->ds_enable = pm->ds_enable_user && !monitor;
6196c92544dSBjoern A. Zeeb mt76_connac_mcu_set_deep_sleep(&dev->mt76, pm->ds_enable);
6206c92544dSBjoern A. Zeeb }
6216c92544dSBjoern A. Zeeb
mt7921_config(struct ieee80211_hw * hw,u32 changed)6226c92544dSBjoern A. Zeeb static int mt7921_config(struct ieee80211_hw *hw, u32 changed)
6236c92544dSBjoern A. Zeeb {
624cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
625cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
6266c92544dSBjoern A. Zeeb int ret = 0;
6276c92544dSBjoern A. Zeeb
6286c92544dSBjoern A. Zeeb if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
629*8ba4d145SBjoern A. Zeeb ret = mt76_update_channel(phy->mt76);
6306c92544dSBjoern A. Zeeb if (ret)
6316c92544dSBjoern A. Zeeb return ret;
6326c92544dSBjoern A. Zeeb }
6336c92544dSBjoern A. Zeeb
634cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
6356c92544dSBjoern A. Zeeb
6366c92544dSBjoern A. Zeeb if (changed & IEEE80211_CONF_CHANGE_POWER) {
6376c92544dSBjoern A. Zeeb ret = mt7921_set_tx_sar_pwr(hw, NULL);
6386c92544dSBjoern A. Zeeb if (ret)
6396c92544dSBjoern A. Zeeb goto out;
6406c92544dSBjoern A. Zeeb }
6416c92544dSBjoern A. Zeeb
6426c92544dSBjoern A. Zeeb if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
6436c92544dSBjoern A. Zeeb ieee80211_iterate_active_interfaces(hw,
6446c92544dSBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL,
6456c92544dSBjoern A. Zeeb mt7921_sniffer_interface_iter, dev);
6466c92544dSBjoern A. Zeeb }
6476c92544dSBjoern A. Zeeb
6486c92544dSBjoern A. Zeeb out:
649cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
6506c92544dSBjoern A. Zeeb
6516c92544dSBjoern A. Zeeb return ret;
6526c92544dSBjoern A. Zeeb }
6536c92544dSBjoern A. Zeeb
mt7921_configure_filter(struct ieee80211_hw * hw,unsigned int changed_flags,unsigned int * total_flags,u64 multicast)6546c92544dSBjoern A. Zeeb static void mt7921_configure_filter(struct ieee80211_hw *hw,
6556c92544dSBjoern A. Zeeb unsigned int changed_flags,
6566c92544dSBjoern A. Zeeb unsigned int *total_flags,
6576c92544dSBjoern A. Zeeb u64 multicast)
6586c92544dSBjoern A. Zeeb {
659cbb3ec25SBjoern A. Zeeb #define MT7921_FILTER_FCSFAIL BIT(2)
660cbb3ec25SBjoern A. Zeeb #define MT7921_FILTER_CONTROL BIT(5)
661cbb3ec25SBjoern A. Zeeb #define MT7921_FILTER_OTHER_BSS BIT(6)
662cbb3ec25SBjoern A. Zeeb #define MT7921_FILTER_ENABLE BIT(31)
6636c92544dSBjoern A. Zeeb
664cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
665cbb3ec25SBjoern A. Zeeb u32 flags = MT7921_FILTER_ENABLE;
666cbb3ec25SBjoern A. Zeeb
667cbb3ec25SBjoern A. Zeeb #define MT7921_FILTER(_fif, _type) do { \
668cbb3ec25SBjoern A. Zeeb if (*total_flags & (_fif)) \
669cbb3ec25SBjoern A. Zeeb flags |= MT7921_FILTER_##_type; \
6706c92544dSBjoern A. Zeeb } while (0)
6716c92544dSBjoern A. Zeeb
672cbb3ec25SBjoern A. Zeeb MT7921_FILTER(FIF_FCSFAIL, FCSFAIL);
673cbb3ec25SBjoern A. Zeeb MT7921_FILTER(FIF_CONTROL, CONTROL);
674cbb3ec25SBjoern A. Zeeb MT7921_FILTER(FIF_OTHER_BSS, OTHER_BSS);
6756c92544dSBjoern A. Zeeb
676cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
677cbb3ec25SBjoern A. Zeeb mt7921_mcu_set_rxfilter(dev, flags, 0, 0);
678cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
6796c92544dSBjoern A. Zeeb
680cbb3ec25SBjoern A. Zeeb *total_flags &= (FIF_OTHER_BSS | FIF_FCSFAIL | FIF_CONTROL);
6816c92544dSBjoern A. Zeeb }
6826c92544dSBjoern A. Zeeb
mt7921_bss_info_changed(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * info,u64 changed)6836c92544dSBjoern A. Zeeb static void mt7921_bss_info_changed(struct ieee80211_hw *hw,
6846c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
6856c92544dSBjoern A. Zeeb struct ieee80211_bss_conf *info,
6866c92544dSBjoern A. Zeeb u64 changed)
6876c92544dSBjoern A. Zeeb {
688cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
689cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
6906c92544dSBjoern A. Zeeb
691cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
6926c92544dSBjoern A. Zeeb
6936c92544dSBjoern A. Zeeb if (changed & BSS_CHANGED_ERP_SLOT) {
6946c92544dSBjoern A. Zeeb int slottime = info->use_short_slot ? 9 : 20;
6956c92544dSBjoern A. Zeeb
6966c92544dSBjoern A. Zeeb if (slottime != phy->slottime) {
6976c92544dSBjoern A. Zeeb phy->slottime = slottime;
698cbb3ec25SBjoern A. Zeeb mt792x_mac_set_timeing(phy);
6996c92544dSBjoern A. Zeeb }
7006c92544dSBjoern A. Zeeb }
7016c92544dSBjoern A. Zeeb
7026c92544dSBjoern A. Zeeb if (changed & (BSS_CHANGED_BEACON |
7036c92544dSBjoern A. Zeeb BSS_CHANGED_BEACON_ENABLED))
7046c92544dSBjoern A. Zeeb mt7921_mcu_uni_add_beacon_offload(dev, hw, vif,
7056c92544dSBjoern A. Zeeb info->enable_beacon);
7066c92544dSBjoern A. Zeeb
7076c92544dSBjoern A. Zeeb /* ensure that enable txcmd_mode after bss_info */
7086c92544dSBjoern A. Zeeb if (changed & (BSS_CHANGED_QOS | BSS_CHANGED_BEACON_ENABLED))
7096c92544dSBjoern A. Zeeb mt7921_mcu_set_tx(dev, vif);
7106c92544dSBjoern A. Zeeb
7116c92544dSBjoern A. Zeeb if (changed & BSS_CHANGED_PS)
7126c92544dSBjoern A. Zeeb mt7921_mcu_uni_bss_ps(dev, vif);
7136c92544dSBjoern A. Zeeb
714*8ba4d145SBjoern A. Zeeb if (changed & BSS_CHANGED_CQM)
715*8ba4d145SBjoern A. Zeeb mt7921_mcu_set_rssimonitor(dev, vif);
716*8ba4d145SBjoern A. Zeeb
7176c92544dSBjoern A. Zeeb if (changed & BSS_CHANGED_ASSOC) {
7186c92544dSBjoern A. Zeeb mt7921_mcu_sta_update(dev, NULL, vif, true,
7196c92544dSBjoern A. Zeeb MT76_STA_INFO_STATE_ASSOC);
7206c92544dSBjoern A. Zeeb mt7921_mcu_set_beacon_filter(dev, vif, vif->cfg.assoc);
7216c92544dSBjoern A. Zeeb }
7226c92544dSBjoern A. Zeeb
7236c92544dSBjoern A. Zeeb if (changed & BSS_CHANGED_ARP_FILTER) {
724cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
7256c92544dSBjoern A. Zeeb
726*8ba4d145SBjoern A. Zeeb mt76_connac_mcu_update_arp_filter(&dev->mt76, &mvif->bss_conf.mt76,
7276c92544dSBjoern A. Zeeb info);
7286c92544dSBjoern A. Zeeb }
7296c92544dSBjoern A. Zeeb
730cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
7316c92544dSBjoern A. Zeeb }
7326c92544dSBjoern A. Zeeb
733*8ba4d145SBjoern A. Zeeb static void
mt7921_calc_vif_num(void * priv,u8 * mac,struct ieee80211_vif * vif)734*8ba4d145SBjoern A. Zeeb mt7921_calc_vif_num(void *priv, u8 *mac, struct ieee80211_vif *vif)
735*8ba4d145SBjoern A. Zeeb {
736*8ba4d145SBjoern A. Zeeb u32 *num = priv;
737*8ba4d145SBjoern A. Zeeb
738*8ba4d145SBjoern A. Zeeb if (!priv)
739*8ba4d145SBjoern A. Zeeb return;
740*8ba4d145SBjoern A. Zeeb
741*8ba4d145SBjoern A. Zeeb switch (vif->type) {
742*8ba4d145SBjoern A. Zeeb case NL80211_IFTYPE_STATION:
743*8ba4d145SBjoern A. Zeeb case NL80211_IFTYPE_P2P_CLIENT:
744*8ba4d145SBjoern A. Zeeb case NL80211_IFTYPE_AP:
745*8ba4d145SBjoern A. Zeeb case NL80211_IFTYPE_P2P_GO:
746*8ba4d145SBjoern A. Zeeb *num += 1;
747*8ba4d145SBjoern A. Zeeb break;
748*8ba4d145SBjoern A. Zeeb default:
749*8ba4d145SBjoern A. Zeeb break;
750*8ba4d145SBjoern A. Zeeb }
751*8ba4d145SBjoern A. Zeeb }
752*8ba4d145SBjoern A. Zeeb
753*8ba4d145SBjoern A. Zeeb static void
mt7921_regd_set_6ghz_power_type(struct ieee80211_vif * vif,bool is_add)754*8ba4d145SBjoern A. Zeeb mt7921_regd_set_6ghz_power_type(struct ieee80211_vif *vif, bool is_add)
755*8ba4d145SBjoern A. Zeeb {
756*8ba4d145SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
757*8ba4d145SBjoern A. Zeeb struct mt792x_phy *phy = mvif->phy;
758*8ba4d145SBjoern A. Zeeb struct mt792x_dev *dev = phy->dev;
759*8ba4d145SBjoern A. Zeeb u32 valid_vif_num = 0;
760*8ba4d145SBjoern A. Zeeb
761*8ba4d145SBjoern A. Zeeb ieee80211_iterate_active_interfaces(mt76_hw(dev),
762*8ba4d145SBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL,
763*8ba4d145SBjoern A. Zeeb mt7921_calc_vif_num, &valid_vif_num);
764*8ba4d145SBjoern A. Zeeb
765*8ba4d145SBjoern A. Zeeb if (valid_vif_num > 1) {
766*8ba4d145SBjoern A. Zeeb phy->power_type = MT_AP_DEFAULT;
767*8ba4d145SBjoern A. Zeeb goto out;
768*8ba4d145SBjoern A. Zeeb }
769*8ba4d145SBjoern A. Zeeb
770*8ba4d145SBjoern A. Zeeb if (!is_add)
771*8ba4d145SBjoern A. Zeeb vif->bss_conf.power_type = IEEE80211_REG_UNSET_AP;
772*8ba4d145SBjoern A. Zeeb
773*8ba4d145SBjoern A. Zeeb switch (vif->bss_conf.power_type) {
774*8ba4d145SBjoern A. Zeeb case IEEE80211_REG_SP_AP:
775*8ba4d145SBjoern A. Zeeb phy->power_type = MT_AP_SP;
776*8ba4d145SBjoern A. Zeeb break;
777*8ba4d145SBjoern A. Zeeb case IEEE80211_REG_VLP_AP:
778*8ba4d145SBjoern A. Zeeb phy->power_type = MT_AP_VLP;
779*8ba4d145SBjoern A. Zeeb break;
780*8ba4d145SBjoern A. Zeeb case IEEE80211_REG_LPI_AP:
781*8ba4d145SBjoern A. Zeeb phy->power_type = MT_AP_LPI;
782*8ba4d145SBjoern A. Zeeb break;
783*8ba4d145SBjoern A. Zeeb case IEEE80211_REG_UNSET_AP:
784*8ba4d145SBjoern A. Zeeb phy->power_type = MT_AP_UNSET;
785*8ba4d145SBjoern A. Zeeb break;
786*8ba4d145SBjoern A. Zeeb default:
787*8ba4d145SBjoern A. Zeeb phy->power_type = MT_AP_DEFAULT;
788*8ba4d145SBjoern A. Zeeb break;
789*8ba4d145SBjoern A. Zeeb }
790*8ba4d145SBjoern A. Zeeb
791*8ba4d145SBjoern A. Zeeb out:
792*8ba4d145SBjoern A. Zeeb mt7921_mcu_set_clc(dev, dev->mt76.alpha2, dev->country_ie_env);
793*8ba4d145SBjoern A. Zeeb }
794*8ba4d145SBjoern A. Zeeb
mt7921_mac_sta_add(struct mt76_dev * mdev,struct ieee80211_vif * vif,struct ieee80211_sta * sta)7956c92544dSBjoern A. Zeeb int mt7921_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
7966c92544dSBjoern A. Zeeb struct ieee80211_sta *sta)
7976c92544dSBjoern A. Zeeb {
798cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
799cbb3ec25SBjoern A. Zeeb struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
800cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
8016c92544dSBjoern A. Zeeb int ret, idx;
8026c92544dSBjoern A. Zeeb
803cbb3ec25SBjoern A. Zeeb idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT792x_WTBL_STA - 1);
8046c92544dSBjoern A. Zeeb if (idx < 0)
8056c92544dSBjoern A. Zeeb return -ENOSPC;
8066c92544dSBjoern A. Zeeb
807*8ba4d145SBjoern A. Zeeb INIT_LIST_HEAD(&msta->deflink.wcid.poll_list);
8086c92544dSBjoern A. Zeeb msta->vif = mvif;
809*8ba4d145SBjoern A. Zeeb msta->deflink.wcid.sta = 1;
810*8ba4d145SBjoern A. Zeeb msta->deflink.wcid.idx = idx;
811*8ba4d145SBjoern A. Zeeb msta->deflink.wcid.phy_idx = mvif->bss_conf.mt76.band_idx;
812*8ba4d145SBjoern A. Zeeb msta->deflink.wcid.tx_info |= MT_WCID_TX_INFO_SET;
813*8ba4d145SBjoern A. Zeeb msta->deflink.last_txs = jiffies;
8146c92544dSBjoern A. Zeeb
8156c92544dSBjoern A. Zeeb ret = mt76_connac_pm_wake(&dev->mphy, &dev->pm);
8166c92544dSBjoern A. Zeeb if (ret)
8176c92544dSBjoern A. Zeeb return ret;
8186c92544dSBjoern A. Zeeb
8196c92544dSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION)
8206c92544dSBjoern A. Zeeb mvif->wep_sta = msta;
8216c92544dSBjoern A. Zeeb
8226c92544dSBjoern A. Zeeb mt7921_mac_wtbl_update(dev, idx,
8236c92544dSBjoern A. Zeeb MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
8246c92544dSBjoern A. Zeeb
8256c92544dSBjoern A. Zeeb ret = mt7921_mcu_sta_update(dev, sta, vif, true,
8266c92544dSBjoern A. Zeeb MT76_STA_INFO_STATE_NONE);
8276c92544dSBjoern A. Zeeb if (ret)
8286c92544dSBjoern A. Zeeb return ret;
8296c92544dSBjoern A. Zeeb
830*8ba4d145SBjoern A. Zeeb mt7921_regd_set_6ghz_power_type(vif, true);
831*8ba4d145SBjoern A. Zeeb
8326c92544dSBjoern A. Zeeb mt76_connac_power_save_sched(&dev->mphy, &dev->pm);
8336c92544dSBjoern A. Zeeb
8346c92544dSBjoern A. Zeeb return 0;
8356c92544dSBjoern A. Zeeb }
8366c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt7921_mac_sta_add);
8376c92544dSBjoern A. Zeeb
mt7921_mac_sta_event(struct mt76_dev * mdev,struct ieee80211_vif * vif,struct ieee80211_sta * sta,enum mt76_sta_event ev)838*8ba4d145SBjoern A. Zeeb int mt7921_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif,
839*8ba4d145SBjoern A. Zeeb struct ieee80211_sta *sta, enum mt76_sta_event ev)
8406c92544dSBjoern A. Zeeb {
841cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
842cbb3ec25SBjoern A. Zeeb struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
843cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
8446c92544dSBjoern A. Zeeb
845*8ba4d145SBjoern A. Zeeb if (ev != MT76_STA_EVENT_ASSOC)
846*8ba4d145SBjoern A. Zeeb return 0;
847*8ba4d145SBjoern A. Zeeb
848cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
8496c92544dSBjoern A. Zeeb
8506c92544dSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
851*8ba4d145SBjoern A. Zeeb mt76_connac_mcu_uni_add_bss(&dev->mphy, vif, &mvif->sta.deflink.wcid,
852*8ba4d145SBjoern A. Zeeb true, mvif->bss_conf.mt76.ctx);
853cbb3ec25SBjoern A. Zeeb
854*8ba4d145SBjoern A. Zeeb ewma_avg_signal_init(&msta->deflink.avg_ack_signal);
8556c92544dSBjoern A. Zeeb
856*8ba4d145SBjoern A. Zeeb mt7921_mac_wtbl_update(dev, msta->deflink.wcid.idx,
8576c92544dSBjoern A. Zeeb MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
858*8ba4d145SBjoern A. Zeeb memset(msta->deflink.airtime_ac, 0, sizeof(msta->deflink.airtime_ac));
8596c92544dSBjoern A. Zeeb
8606c92544dSBjoern A. Zeeb mt7921_mcu_sta_update(dev, sta, vif, true, MT76_STA_INFO_STATE_ASSOC);
8616c92544dSBjoern A. Zeeb
862cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
863*8ba4d145SBjoern A. Zeeb
864*8ba4d145SBjoern A. Zeeb return 0;
8656c92544dSBjoern A. Zeeb }
866*8ba4d145SBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt7921_mac_sta_event);
8676c92544dSBjoern A. Zeeb
mt7921_mac_sta_remove(struct mt76_dev * mdev,struct ieee80211_vif * vif,struct ieee80211_sta * sta)8686c92544dSBjoern A. Zeeb void mt7921_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
8696c92544dSBjoern A. Zeeb struct ieee80211_sta *sta)
8706c92544dSBjoern A. Zeeb {
871cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
872cbb3ec25SBjoern A. Zeeb struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
8736c92544dSBjoern A. Zeeb
874*8ba4d145SBjoern A. Zeeb mt7921_roc_abort_sync(dev);
875*8ba4d145SBjoern A. Zeeb mt76_connac_free_pending_tx_skbs(&dev->pm, &msta->deflink.wcid);
8766c92544dSBjoern A. Zeeb mt76_connac_pm_wake(&dev->mphy, &dev->pm);
8776c92544dSBjoern A. Zeeb
8786c92544dSBjoern A. Zeeb mt7921_mcu_sta_update(dev, sta, vif, false, MT76_STA_INFO_STATE_NONE);
879*8ba4d145SBjoern A. Zeeb mt7921_mac_wtbl_update(dev, msta->deflink.wcid.idx,
8806c92544dSBjoern A. Zeeb MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
8816c92544dSBjoern A. Zeeb
8826c92544dSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION) {
883cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
8846c92544dSBjoern A. Zeeb
8856c92544dSBjoern A. Zeeb mvif->wep_sta = NULL;
886*8ba4d145SBjoern A. Zeeb ewma_rssi_init(&mvif->bss_conf.rssi);
8876c92544dSBjoern A. Zeeb if (!sta->tdls)
8886c92544dSBjoern A. Zeeb mt76_connac_mcu_uni_add_bss(&dev->mphy, vif,
889*8ba4d145SBjoern A. Zeeb &mvif->sta.deflink.wcid, false,
890*8ba4d145SBjoern A. Zeeb mvif->bss_conf.mt76.ctx);
8916c92544dSBjoern A. Zeeb }
8926c92544dSBjoern A. Zeeb
893cbb3ec25SBjoern A. Zeeb spin_lock_bh(&dev->mt76.sta_poll_lock);
894*8ba4d145SBjoern A. Zeeb if (!list_empty(&msta->deflink.wcid.poll_list))
895*8ba4d145SBjoern A. Zeeb list_del_init(&msta->deflink.wcid.poll_list);
896cbb3ec25SBjoern A. Zeeb spin_unlock_bh(&dev->mt76.sta_poll_lock);
8976c92544dSBjoern A. Zeeb
898*8ba4d145SBjoern A. Zeeb mt7921_regd_set_6ghz_power_type(vif, false);
899*8ba4d145SBjoern A. Zeeb
9006c92544dSBjoern A. Zeeb mt76_connac_power_save_sched(&dev->mphy, &dev->pm);
9016c92544dSBjoern A. Zeeb }
9026c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt7921_mac_sta_remove);
9036c92544dSBjoern A. Zeeb
mt7921_set_rts_threshold(struct ieee80211_hw * hw,u32 val)9046c92544dSBjoern A. Zeeb static int mt7921_set_rts_threshold(struct ieee80211_hw *hw, u32 val)
9056c92544dSBjoern A. Zeeb {
906cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
9076c92544dSBjoern A. Zeeb
908cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
9096c92544dSBjoern A. Zeeb mt76_connac_mcu_set_rts_thresh(&dev->mt76, val, 0);
910cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
9116c92544dSBjoern A. Zeeb
9126c92544dSBjoern A. Zeeb return 0;
9136c92544dSBjoern A. Zeeb }
9146c92544dSBjoern A. Zeeb
9156c92544dSBjoern A. Zeeb static int
mt7921_ampdu_action(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_ampdu_params * params)9166c92544dSBjoern A. Zeeb mt7921_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
9176c92544dSBjoern A. Zeeb struct ieee80211_ampdu_params *params)
9186c92544dSBjoern A. Zeeb {
9196c92544dSBjoern A. Zeeb enum ieee80211_ampdu_mlme_action action = params->action;
920cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
9216c92544dSBjoern A. Zeeb struct ieee80211_sta *sta = params->sta;
9226c92544dSBjoern A. Zeeb struct ieee80211_txq *txq = sta->txq[params->tid];
923cbb3ec25SBjoern A. Zeeb struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
9246c92544dSBjoern A. Zeeb u16 tid = params->tid;
9256c92544dSBjoern A. Zeeb u16 ssn = params->ssn;
9266c92544dSBjoern A. Zeeb struct mt76_txq *mtxq;
9276c92544dSBjoern A. Zeeb int ret = 0;
9286c92544dSBjoern A. Zeeb
9296c92544dSBjoern A. Zeeb if (!txq)
9306c92544dSBjoern A. Zeeb return -EINVAL;
9316c92544dSBjoern A. Zeeb
9326c92544dSBjoern A. Zeeb mtxq = (struct mt76_txq *)txq->drv_priv;
9336c92544dSBjoern A. Zeeb
934cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
9356c92544dSBjoern A. Zeeb switch (action) {
9366c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_RX_START:
937*8ba4d145SBjoern A. Zeeb mt76_rx_aggr_start(&dev->mt76, &msta->deflink.wcid, tid, ssn,
9386c92544dSBjoern A. Zeeb params->buf_size);
9396c92544dSBjoern A. Zeeb mt7921_mcu_uni_rx_ba(dev, params, true);
9406c92544dSBjoern A. Zeeb break;
9416c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_RX_STOP:
942*8ba4d145SBjoern A. Zeeb mt76_rx_aggr_stop(&dev->mt76, &msta->deflink.wcid, tid);
9436c92544dSBjoern A. Zeeb mt7921_mcu_uni_rx_ba(dev, params, false);
9446c92544dSBjoern A. Zeeb break;
9456c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_OPERATIONAL:
9466c92544dSBjoern A. Zeeb mtxq->aggr = true;
9476c92544dSBjoern A. Zeeb mtxq->send_bar = false;
9486c92544dSBjoern A. Zeeb mt7921_mcu_uni_tx_ba(dev, params, true);
9496c92544dSBjoern A. Zeeb break;
9506c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_STOP_FLUSH:
9516c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
9526c92544dSBjoern A. Zeeb mtxq->aggr = false;
953*8ba4d145SBjoern A. Zeeb clear_bit(tid, &msta->deflink.wcid.ampdu_state);
9546c92544dSBjoern A. Zeeb mt7921_mcu_uni_tx_ba(dev, params, false);
9556c92544dSBjoern A. Zeeb break;
9566c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_START:
957*8ba4d145SBjoern A. Zeeb set_bit(tid, &msta->deflink.wcid.ampdu_state);
9586c92544dSBjoern A. Zeeb ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;
9596c92544dSBjoern A. Zeeb break;
9606c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_STOP_CONT:
9616c92544dSBjoern A. Zeeb mtxq->aggr = false;
962*8ba4d145SBjoern A. Zeeb clear_bit(tid, &msta->deflink.wcid.ampdu_state);
9636c92544dSBjoern A. Zeeb mt7921_mcu_uni_tx_ba(dev, params, false);
9646c92544dSBjoern A. Zeeb ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
9656c92544dSBjoern A. Zeeb break;
9666c92544dSBjoern A. Zeeb }
967cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
9686c92544dSBjoern A. Zeeb
9696c92544dSBjoern A. Zeeb return ret;
9706c92544dSBjoern A. Zeeb }
9716c92544dSBjoern A. Zeeb
mt7921_sta_state(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta,enum ieee80211_sta_state old_state,enum ieee80211_sta_state new_state)9726c92544dSBjoern A. Zeeb static int mt7921_sta_state(struct ieee80211_hw *hw,
9736c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
9746c92544dSBjoern A. Zeeb struct ieee80211_sta *sta,
9756c92544dSBjoern A. Zeeb enum ieee80211_sta_state old_state,
9766c92544dSBjoern A. Zeeb enum ieee80211_sta_state new_state)
9776c92544dSBjoern A. Zeeb {
978cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
9796c92544dSBjoern A. Zeeb
9806c92544dSBjoern A. Zeeb if (dev->pm.ds_enable) {
981cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
9826c92544dSBjoern A. Zeeb mt76_connac_sta_state_dp(&dev->mt76, old_state, new_state);
983cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
9846c92544dSBjoern A. Zeeb }
9856c92544dSBjoern A. Zeeb
9866c92544dSBjoern A. Zeeb return mt76_sta_state(hw, vif, sta, old_state, new_state);
9876c92544dSBjoern A. Zeeb }
9886c92544dSBjoern A. Zeeb
mt7921_scan_work(struct work_struct * work)9896c92544dSBjoern A. Zeeb void mt7921_scan_work(struct work_struct *work)
9906c92544dSBjoern A. Zeeb {
991cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy;
9926c92544dSBjoern A. Zeeb
993cbb3ec25SBjoern A. Zeeb phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy,
9946c92544dSBjoern A. Zeeb scan_work.work);
9956c92544dSBjoern A. Zeeb
9966c92544dSBjoern A. Zeeb while (true) {
9976c92544dSBjoern A. Zeeb struct mt76_connac2_mcu_rxd *rxd;
9986c92544dSBjoern A. Zeeb struct sk_buff *skb;
9996c92544dSBjoern A. Zeeb
10006c92544dSBjoern A. Zeeb spin_lock_bh(&phy->dev->mt76.lock);
10016c92544dSBjoern A. Zeeb skb = __skb_dequeue(&phy->scan_event_list);
10026c92544dSBjoern A. Zeeb spin_unlock_bh(&phy->dev->mt76.lock);
10036c92544dSBjoern A. Zeeb
10046c92544dSBjoern A. Zeeb if (!skb)
10056c92544dSBjoern A. Zeeb break;
10066c92544dSBjoern A. Zeeb
10076c92544dSBjoern A. Zeeb rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
10086c92544dSBjoern A. Zeeb if (rxd->eid == MCU_EVENT_SCHED_SCAN_DONE) {
10096c92544dSBjoern A. Zeeb ieee80211_sched_scan_results(phy->mt76->hw);
10106c92544dSBjoern A. Zeeb } else if (test_and_clear_bit(MT76_HW_SCANNING,
10116c92544dSBjoern A. Zeeb &phy->mt76->state)) {
10126c92544dSBjoern A. Zeeb struct cfg80211_scan_info info = {
10136c92544dSBjoern A. Zeeb .aborted = false,
10146c92544dSBjoern A. Zeeb };
10156c92544dSBjoern A. Zeeb
10166c92544dSBjoern A. Zeeb ieee80211_scan_completed(phy->mt76->hw, &info);
10176c92544dSBjoern A. Zeeb }
10186c92544dSBjoern A. Zeeb dev_kfree_skb(skb);
10196c92544dSBjoern A. Zeeb }
10206c92544dSBjoern A. Zeeb }
10216c92544dSBjoern A. Zeeb
10226c92544dSBjoern A. Zeeb static int
mt7921_hw_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_scan_request * req)10236c92544dSBjoern A. Zeeb mt7921_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
10246c92544dSBjoern A. Zeeb struct ieee80211_scan_request *req)
10256c92544dSBjoern A. Zeeb {
1026cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
10276c92544dSBjoern A. Zeeb struct mt76_phy *mphy = hw->priv;
10286c92544dSBjoern A. Zeeb int err;
10296c92544dSBjoern A. Zeeb
1030cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
10316c92544dSBjoern A. Zeeb err = mt76_connac_mcu_hw_scan(mphy, vif, req);
1032cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
10336c92544dSBjoern A. Zeeb
10346c92544dSBjoern A. Zeeb return err;
10356c92544dSBjoern A. Zeeb }
10366c92544dSBjoern A. Zeeb
10376c92544dSBjoern A. Zeeb static void
mt7921_cancel_hw_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif)10386c92544dSBjoern A. Zeeb mt7921_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
10396c92544dSBjoern A. Zeeb {
1040cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
10416c92544dSBjoern A. Zeeb struct mt76_phy *mphy = hw->priv;
10426c92544dSBjoern A. Zeeb
1043cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
10446c92544dSBjoern A. Zeeb mt76_connac_mcu_cancel_hw_scan(mphy, vif);
1045cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
10466c92544dSBjoern A. Zeeb }
10476c92544dSBjoern A. Zeeb
10486c92544dSBjoern A. Zeeb static int
mt7921_start_sched_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct cfg80211_sched_scan_request * req,struct ieee80211_scan_ies * ies)10496c92544dSBjoern A. Zeeb mt7921_start_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
10506c92544dSBjoern A. Zeeb struct cfg80211_sched_scan_request *req,
10516c92544dSBjoern A. Zeeb struct ieee80211_scan_ies *ies)
10526c92544dSBjoern A. Zeeb {
1053cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
10546c92544dSBjoern A. Zeeb struct mt76_phy *mphy = hw->priv;
10556c92544dSBjoern A. Zeeb int err;
10566c92544dSBjoern A. Zeeb
1057cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
10586c92544dSBjoern A. Zeeb
10596c92544dSBjoern A. Zeeb err = mt76_connac_mcu_sched_scan_req(mphy, vif, req);
10606c92544dSBjoern A. Zeeb if (err < 0)
10616c92544dSBjoern A. Zeeb goto out;
10626c92544dSBjoern A. Zeeb
10636c92544dSBjoern A. Zeeb err = mt76_connac_mcu_sched_scan_enable(mphy, vif, true);
10646c92544dSBjoern A. Zeeb out:
1065cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
10666c92544dSBjoern A. Zeeb
10676c92544dSBjoern A. Zeeb return err;
10686c92544dSBjoern A. Zeeb }
10696c92544dSBjoern A. Zeeb
10706c92544dSBjoern A. Zeeb static int
mt7921_stop_sched_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif)10716c92544dSBjoern A. Zeeb mt7921_stop_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
10726c92544dSBjoern A. Zeeb {
1073cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
10746c92544dSBjoern A. Zeeb struct mt76_phy *mphy = hw->priv;
10756c92544dSBjoern A. Zeeb int err;
10766c92544dSBjoern A. Zeeb
1077cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
10786c92544dSBjoern A. Zeeb err = mt76_connac_mcu_sched_scan_enable(mphy, vif, false);
1079cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
10806c92544dSBjoern A. Zeeb
10816c92544dSBjoern A. Zeeb return err;
10826c92544dSBjoern A. Zeeb }
10836c92544dSBjoern A. Zeeb
10846c92544dSBjoern A. Zeeb static int
mt7921_set_antenna(struct ieee80211_hw * hw,u32 tx_ant,u32 rx_ant)10856c92544dSBjoern A. Zeeb mt7921_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
10866c92544dSBjoern A. Zeeb {
1087cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
1088cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
10896c92544dSBjoern A. Zeeb int max_nss = hweight8(hw->wiphy->available_antennas_tx);
10906c92544dSBjoern A. Zeeb
10916c92544dSBjoern A. Zeeb if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss)
10926c92544dSBjoern A. Zeeb return -EINVAL;
10936c92544dSBjoern A. Zeeb
10946c92544dSBjoern A. Zeeb if ((BIT(hweight8(tx_ant)) - 1) != tx_ant)
1095cbb3ec25SBjoern A. Zeeb return -EINVAL;
10966c92544dSBjoern A. Zeeb
1097cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
10986c92544dSBjoern A. Zeeb
10996c92544dSBjoern A. Zeeb phy->mt76->antenna_mask = tx_ant;
11006c92544dSBjoern A. Zeeb phy->mt76->chainmask = tx_ant;
11016c92544dSBjoern A. Zeeb
11026c92544dSBjoern A. Zeeb mt76_set_stream_caps(phy->mt76, true);
11036c92544dSBjoern A. Zeeb mt7921_set_stream_he_caps(phy);
11046c92544dSBjoern A. Zeeb
1105cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
11066c92544dSBjoern A. Zeeb
11076c92544dSBjoern A. Zeeb return 0;
11086c92544dSBjoern A. Zeeb }
11096c92544dSBjoern A. Zeeb
11106c92544dSBjoern A. Zeeb #ifdef CONFIG_PM
mt7921_suspend(struct ieee80211_hw * hw,struct cfg80211_wowlan * wowlan)11116c92544dSBjoern A. Zeeb static int mt7921_suspend(struct ieee80211_hw *hw,
11126c92544dSBjoern A. Zeeb struct cfg80211_wowlan *wowlan)
11136c92544dSBjoern A. Zeeb {
1114cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
1115cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
11166c92544dSBjoern A. Zeeb
11176c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&phy->scan_work);
11186c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&phy->mt76->mac_work);
11196c92544dSBjoern A. Zeeb
11206c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&dev->pm.ps_work);
11216c92544dSBjoern A. Zeeb mt76_connac_free_pending_tx_skbs(&dev->pm, NULL);
11226c92544dSBjoern A. Zeeb
1123cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
11246c92544dSBjoern A. Zeeb
11256c92544dSBjoern A. Zeeb clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
11266c92544dSBjoern A. Zeeb ieee80211_iterate_active_interfaces(hw,
11276c92544dSBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL,
11286c92544dSBjoern A. Zeeb mt7921_mcu_set_suspend_iter,
11296c92544dSBjoern A. Zeeb &dev->mphy);
11306c92544dSBjoern A. Zeeb
1131cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
11326c92544dSBjoern A. Zeeb
11336c92544dSBjoern A. Zeeb return 0;
11346c92544dSBjoern A. Zeeb }
11356c92544dSBjoern A. Zeeb
mt7921_resume(struct ieee80211_hw * hw)11366c92544dSBjoern A. Zeeb static int mt7921_resume(struct ieee80211_hw *hw)
11376c92544dSBjoern A. Zeeb {
1138cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
1139cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
11406c92544dSBjoern A. Zeeb
1141cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
11426c92544dSBjoern A. Zeeb
11436c92544dSBjoern A. Zeeb set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
11446c92544dSBjoern A. Zeeb ieee80211_iterate_active_interfaces(hw,
11456c92544dSBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL,
11466c92544dSBjoern A. Zeeb mt76_connac_mcu_set_suspend_iter,
11476c92544dSBjoern A. Zeeb &dev->mphy);
11486c92544dSBjoern A. Zeeb
11496c92544dSBjoern A. Zeeb ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
1150cbb3ec25SBjoern A. Zeeb MT792x_WATCHDOG_TIME);
11516c92544dSBjoern A. Zeeb
1152cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
11536c92544dSBjoern A. Zeeb
11546c92544dSBjoern A. Zeeb return 0;
11556c92544dSBjoern A. Zeeb }
11566c92544dSBjoern A. Zeeb
mt7921_set_rekey_data(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct cfg80211_gtk_rekey_data * data)11576c92544dSBjoern A. Zeeb static void mt7921_set_rekey_data(struct ieee80211_hw *hw,
11586c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
11596c92544dSBjoern A. Zeeb struct cfg80211_gtk_rekey_data *data)
11606c92544dSBjoern A. Zeeb {
1161cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
11626c92544dSBjoern A. Zeeb
1163cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
11646c92544dSBjoern A. Zeeb mt76_connac_mcu_update_gtk_rekey(hw, vif, data);
1165cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
11666c92544dSBjoern A. Zeeb }
11676c92544dSBjoern A. Zeeb #endif /* CONFIG_PM */
11686c92544dSBjoern A. Zeeb
mt7921_sta_set_decap_offload(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta,bool enabled)11696c92544dSBjoern A. Zeeb static void mt7921_sta_set_decap_offload(struct ieee80211_hw *hw,
11706c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
11716c92544dSBjoern A. Zeeb struct ieee80211_sta *sta,
11726c92544dSBjoern A. Zeeb bool enabled)
11736c92544dSBjoern A. Zeeb {
1174cbb3ec25SBjoern A. Zeeb struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
1175cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
11766c92544dSBjoern A. Zeeb
1177cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
11786c92544dSBjoern A. Zeeb
11796c92544dSBjoern A. Zeeb if (enabled)
1180*8ba4d145SBjoern A. Zeeb set_bit(MT_WCID_FLAG_HDR_TRANS, &msta->deflink.wcid.flags);
11816c92544dSBjoern A. Zeeb else
1182*8ba4d145SBjoern A. Zeeb clear_bit(MT_WCID_FLAG_HDR_TRANS, &msta->deflink.wcid.flags);
11836c92544dSBjoern A. Zeeb
1184*8ba4d145SBjoern A. Zeeb mt76_connac_mcu_sta_update_hdr_trans(&dev->mt76, vif, &msta->deflink.wcid,
11856c92544dSBjoern A. Zeeb MCU_UNI_CMD(STA_REC_UPDATE));
11866c92544dSBjoern A. Zeeb
1187cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
11886c92544dSBjoern A. Zeeb }
11896c92544dSBjoern A. Zeeb
11906c92544dSBjoern A. Zeeb #if IS_ENABLED(CONFIG_IPV6)
mt7921_ipv6_addr_change(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct inet6_dev * idev)11916c92544dSBjoern A. Zeeb static void mt7921_ipv6_addr_change(struct ieee80211_hw *hw,
11926c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
11936c92544dSBjoern A. Zeeb struct inet6_dev *idev)
11946c92544dSBjoern A. Zeeb {
1195cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1196*8ba4d145SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
11976c92544dSBjoern A. Zeeb struct inet6_ifaddr *ifa;
11986c92544dSBjoern A. Zeeb struct in6_addr ns_addrs[IEEE80211_BSS_ARP_ADDR_LIST_LEN];
11996c92544dSBjoern A. Zeeb struct sk_buff *skb;
12006c92544dSBjoern A. Zeeb u8 i, idx = 0;
12016c92544dSBjoern A. Zeeb
12026c92544dSBjoern A. Zeeb struct {
12036c92544dSBjoern A. Zeeb struct {
12046c92544dSBjoern A. Zeeb u8 bss_idx;
12056c92544dSBjoern A. Zeeb u8 pad[3];
12066c92544dSBjoern A. Zeeb } __packed hdr;
12076c92544dSBjoern A. Zeeb struct mt76_connac_arpns_tlv arpns;
12086c92544dSBjoern A. Zeeb } req_hdr = {
12096c92544dSBjoern A. Zeeb .hdr = {
1210*8ba4d145SBjoern A. Zeeb .bss_idx = mvif->bss_conf.mt76.idx,
12116c92544dSBjoern A. Zeeb },
12126c92544dSBjoern A. Zeeb .arpns = {
12136c92544dSBjoern A. Zeeb .tag = cpu_to_le16(UNI_OFFLOAD_OFFLOAD_ND),
12146c92544dSBjoern A. Zeeb .mode = 2, /* update */
12156c92544dSBjoern A. Zeeb .option = 1, /* update only */
12166c92544dSBjoern A. Zeeb },
12176c92544dSBjoern A. Zeeb };
12186c92544dSBjoern A. Zeeb
12196c92544dSBjoern A. Zeeb read_lock_bh(&idev->lock);
12206c92544dSBjoern A. Zeeb list_for_each_entry(ifa, &idev->addr_list, if_list) {
12216c92544dSBjoern A. Zeeb if (ifa->flags & IFA_F_TENTATIVE)
12226c92544dSBjoern A. Zeeb continue;
12236c92544dSBjoern A. Zeeb ns_addrs[idx] = ifa->addr;
12246c92544dSBjoern A. Zeeb if (++idx >= IEEE80211_BSS_ARP_ADDR_LIST_LEN)
12256c92544dSBjoern A. Zeeb break;
12266c92544dSBjoern A. Zeeb }
12276c92544dSBjoern A. Zeeb read_unlock_bh(&idev->lock);
12286c92544dSBjoern A. Zeeb
12296c92544dSBjoern A. Zeeb if (!idx)
12306c92544dSBjoern A. Zeeb return;
12316c92544dSBjoern A. Zeeb
12326c92544dSBjoern A. Zeeb req_hdr.arpns.ips_num = idx;
12336c92544dSBjoern A. Zeeb req_hdr.arpns.len = cpu_to_le16(sizeof(struct mt76_connac_arpns_tlv)
12346c92544dSBjoern A. Zeeb + idx * sizeof(struct in6_addr));
12356c92544dSBjoern A. Zeeb skb = __mt76_mcu_msg_alloc(&dev->mt76, &req_hdr,
12366c92544dSBjoern A. Zeeb sizeof(req_hdr) + idx * sizeof(struct in6_addr),
12376c92544dSBjoern A. Zeeb sizeof(req_hdr), GFP_ATOMIC);
12386c92544dSBjoern A. Zeeb if (!skb)
12396c92544dSBjoern A. Zeeb return;
12406c92544dSBjoern A. Zeeb
12416c92544dSBjoern A. Zeeb for (i = 0; i < idx; i++)
12426c92544dSBjoern A. Zeeb skb_put_data(skb, &ns_addrs[i].in6_u, sizeof(struct in6_addr));
12436c92544dSBjoern A. Zeeb
12446c92544dSBjoern A. Zeeb skb_queue_tail(&dev->ipv6_ns_list, skb);
12456c92544dSBjoern A. Zeeb
12466c92544dSBjoern A. Zeeb ieee80211_queue_work(dev->mt76.hw, &dev->ipv6_ns_work);
12476c92544dSBjoern A. Zeeb }
12486c92544dSBjoern A. Zeeb #endif
12496c92544dSBjoern A. Zeeb
mt7921_set_tx_sar_pwr(struct ieee80211_hw * hw,const struct cfg80211_sar_specs * sar)12506c92544dSBjoern A. Zeeb int mt7921_set_tx_sar_pwr(struct ieee80211_hw *hw,
12516c92544dSBjoern A. Zeeb const struct cfg80211_sar_specs *sar)
12526c92544dSBjoern A. Zeeb {
12536c92544dSBjoern A. Zeeb struct mt76_phy *mphy = hw->priv;
12546c92544dSBjoern A. Zeeb
12556c92544dSBjoern A. Zeeb if (sar) {
1256cbb3ec25SBjoern A. Zeeb int err = mt76_init_sar_power(hw, sar);
1257cbb3ec25SBjoern A. Zeeb
12586c92544dSBjoern A. Zeeb if (err)
12596c92544dSBjoern A. Zeeb return err;
12606c92544dSBjoern A. Zeeb }
1261cbb3ec25SBjoern A. Zeeb mt792x_init_acpi_sar_power(mt792x_hw_phy(hw), !sar);
12626c92544dSBjoern A. Zeeb
1263cbb3ec25SBjoern A. Zeeb return mt76_connac_mcu_set_rate_txpower(mphy);
12646c92544dSBjoern A. Zeeb }
12656c92544dSBjoern A. Zeeb
mt7921_set_sar_specs(struct ieee80211_hw * hw,const struct cfg80211_sar_specs * sar)12666c92544dSBjoern A. Zeeb static int mt7921_set_sar_specs(struct ieee80211_hw *hw,
12676c92544dSBjoern A. Zeeb const struct cfg80211_sar_specs *sar)
12686c92544dSBjoern A. Zeeb {
1269cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
12706c92544dSBjoern A. Zeeb int err;
12716c92544dSBjoern A. Zeeb
1272cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
1273cbb3ec25SBjoern A. Zeeb err = mt7921_mcu_set_clc(dev, dev->mt76.alpha2,
1274cbb3ec25SBjoern A. Zeeb dev->country_ie_env);
1275cbb3ec25SBjoern A. Zeeb if (err < 0)
1276cbb3ec25SBjoern A. Zeeb goto out;
1277cbb3ec25SBjoern A. Zeeb
12786c92544dSBjoern A. Zeeb err = mt7921_set_tx_sar_pwr(hw, sar);
1279cbb3ec25SBjoern A. Zeeb out:
1280cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
12816c92544dSBjoern A. Zeeb
12826c92544dSBjoern A. Zeeb return err;
12836c92544dSBjoern A. Zeeb }
12846c92544dSBjoern A. Zeeb
12856c92544dSBjoern A. Zeeb static void
mt7921_channel_switch_beacon(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct cfg80211_chan_def * chandef)12866c92544dSBjoern A. Zeeb mt7921_channel_switch_beacon(struct ieee80211_hw *hw,
12876c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
12886c92544dSBjoern A. Zeeb struct cfg80211_chan_def *chandef)
12896c92544dSBjoern A. Zeeb {
1290cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
12916c92544dSBjoern A. Zeeb
1292cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
12936c92544dSBjoern A. Zeeb mt7921_mcu_uni_add_beacon_offload(dev, hw, vif, true);
1294cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
12956c92544dSBjoern A. Zeeb }
12966c92544dSBjoern A. Zeeb
12976c92544dSBjoern A. Zeeb static int
mt7921_start_ap(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)12986c92544dSBjoern A. Zeeb mt7921_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
12996c92544dSBjoern A. Zeeb struct ieee80211_bss_conf *link_conf)
13006c92544dSBjoern A. Zeeb {
1301cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1302cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
1303cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
13046c92544dSBjoern A. Zeeb int err;
13056c92544dSBjoern A. Zeeb
1306cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
13076c92544dSBjoern A. Zeeb
1308*8ba4d145SBjoern A. Zeeb err = mt76_connac_mcu_uni_add_bss(phy->mt76, vif, &mvif->sta.deflink.wcid,
1309*8ba4d145SBjoern A. Zeeb true, mvif->bss_conf.mt76.ctx);
13106c92544dSBjoern A. Zeeb if (err)
13116c92544dSBjoern A. Zeeb goto out;
13126c92544dSBjoern A. Zeeb
13136c92544dSBjoern A. Zeeb err = mt7921_mcu_set_bss_pm(dev, vif, true);
13146c92544dSBjoern A. Zeeb if (err)
13156c92544dSBjoern A. Zeeb goto out;
13166c92544dSBjoern A. Zeeb
13176c92544dSBjoern A. Zeeb err = mt7921_mcu_sta_update(dev, NULL, vif, true,
13186c92544dSBjoern A. Zeeb MT76_STA_INFO_STATE_NONE);
13196c92544dSBjoern A. Zeeb out:
1320cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
13216c92544dSBjoern A. Zeeb
13226c92544dSBjoern A. Zeeb return err;
13236c92544dSBjoern A. Zeeb }
13246c92544dSBjoern A. Zeeb
13256c92544dSBjoern A. Zeeb static void
mt7921_stop_ap(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)13266c92544dSBjoern A. Zeeb mt7921_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
13276c92544dSBjoern A. Zeeb struct ieee80211_bss_conf *link_conf)
13286c92544dSBjoern A. Zeeb {
1329cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1330cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
1331cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
13326c92544dSBjoern A. Zeeb int err;
13336c92544dSBjoern A. Zeeb
1334cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
13356c92544dSBjoern A. Zeeb
13366c92544dSBjoern A. Zeeb err = mt7921_mcu_set_bss_pm(dev, vif, false);
13376c92544dSBjoern A. Zeeb if (err)
13386c92544dSBjoern A. Zeeb goto out;
13396c92544dSBjoern A. Zeeb
1340*8ba4d145SBjoern A. Zeeb mt76_connac_mcu_uni_add_bss(phy->mt76, vif, &mvif->sta.deflink.wcid, false,
1341*8ba4d145SBjoern A. Zeeb mvif->bss_conf.mt76.ctx);
13426c92544dSBjoern A. Zeeb
13436c92544dSBjoern A. Zeeb out:
1344cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
1345cbb3ec25SBjoern A. Zeeb }
1346cbb3ec25SBjoern A. Zeeb
1347cbb3ec25SBjoern A. Zeeb static int
mt7921_add_chanctx(struct ieee80211_hw * hw,struct ieee80211_chanctx_conf * ctx)1348cbb3ec25SBjoern A. Zeeb mt7921_add_chanctx(struct ieee80211_hw *hw,
1349cbb3ec25SBjoern A. Zeeb struct ieee80211_chanctx_conf *ctx)
1350cbb3ec25SBjoern A. Zeeb {
1351*8ba4d145SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
1352*8ba4d145SBjoern A. Zeeb
1353*8ba4d145SBjoern A. Zeeb dev->new_ctx = ctx;
1354cbb3ec25SBjoern A. Zeeb return 0;
1355cbb3ec25SBjoern A. Zeeb }
1356cbb3ec25SBjoern A. Zeeb
1357cbb3ec25SBjoern A. Zeeb static void
mt7921_remove_chanctx(struct ieee80211_hw * hw,struct ieee80211_chanctx_conf * ctx)1358cbb3ec25SBjoern A. Zeeb mt7921_remove_chanctx(struct ieee80211_hw *hw,
1359cbb3ec25SBjoern A. Zeeb struct ieee80211_chanctx_conf *ctx)
1360cbb3ec25SBjoern A. Zeeb {
1361*8ba4d145SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
1362cbb3ec25SBjoern A. Zeeb
1363*8ba4d145SBjoern A. Zeeb if (dev->new_ctx == ctx)
1364*8ba4d145SBjoern A. Zeeb dev->new_ctx = NULL;
1365cbb3ec25SBjoern A. Zeeb }
1366cbb3ec25SBjoern A. Zeeb
1367cbb3ec25SBjoern A. Zeeb static void
mt7921_change_chanctx(struct ieee80211_hw * hw,struct ieee80211_chanctx_conf * ctx,u32 changed)1368cbb3ec25SBjoern A. Zeeb mt7921_change_chanctx(struct ieee80211_hw *hw,
1369cbb3ec25SBjoern A. Zeeb struct ieee80211_chanctx_conf *ctx,
1370cbb3ec25SBjoern A. Zeeb u32 changed)
1371cbb3ec25SBjoern A. Zeeb {
1372*8ba4d145SBjoern A. Zeeb struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv;
1373cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
1374*8ba4d145SBjoern A. Zeeb struct ieee80211_vif *vif;
1375*8ba4d145SBjoern A. Zeeb struct mt792x_vif *mvif;
1376*8ba4d145SBjoern A. Zeeb
1377*8ba4d145SBjoern A. Zeeb if (!mctx->bss_conf)
1378*8ba4d145SBjoern A. Zeeb return;
1379*8ba4d145SBjoern A. Zeeb
1380*8ba4d145SBjoern A. Zeeb mvif = container_of(mctx->bss_conf, struct mt792x_vif, bss_conf);
1381*8ba4d145SBjoern A. Zeeb vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv);
1382cbb3ec25SBjoern A. Zeeb
1383cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(phy->dev);
1384*8ba4d145SBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_MONITOR)
1385*8ba4d145SBjoern A. Zeeb mt7921_mcu_config_sniffer(mvif, ctx);
1386*8ba4d145SBjoern A. Zeeb else
1387*8ba4d145SBjoern A. Zeeb mt76_connac_mcu_uni_set_chctx(mvif->phy->mt76, &mvif->bss_conf.mt76, ctx);
1388cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(phy->dev);
1389cbb3ec25SBjoern A. Zeeb }
1390cbb3ec25SBjoern A. Zeeb
mt7921_mgd_prepare_tx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_prep_tx_info * info)1391cbb3ec25SBjoern A. Zeeb static void mt7921_mgd_prepare_tx(struct ieee80211_hw *hw,
1392cbb3ec25SBjoern A. Zeeb struct ieee80211_vif *vif,
1393cbb3ec25SBjoern A. Zeeb struct ieee80211_prep_tx_info *info)
1394cbb3ec25SBjoern A. Zeeb {
1395cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1396cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
1397cbb3ec25SBjoern A. Zeeb u16 duration = info->duration ? info->duration :
1398cbb3ec25SBjoern A. Zeeb jiffies_to_msecs(HZ);
1399cbb3ec25SBjoern A. Zeeb
1400cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
1401*8ba4d145SBjoern A. Zeeb mt7921_set_roc(mvif->phy, mvif, mvif->bss_conf.mt76.ctx->def.chan, duration,
1402cbb3ec25SBjoern A. Zeeb MT7921_ROC_REQ_JOIN);
1403cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
1404cbb3ec25SBjoern A. Zeeb }
1405cbb3ec25SBjoern A. Zeeb
mt7921_mgd_complete_tx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_prep_tx_info * info)1406cbb3ec25SBjoern A. Zeeb static void mt7921_mgd_complete_tx(struct ieee80211_hw *hw,
1407cbb3ec25SBjoern A. Zeeb struct ieee80211_vif *vif,
1408cbb3ec25SBjoern A. Zeeb struct ieee80211_prep_tx_info *info)
1409cbb3ec25SBjoern A. Zeeb {
1410cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1411cbb3ec25SBjoern A. Zeeb
1412cbb3ec25SBjoern A. Zeeb mt7921_abort_roc(mvif->phy, mvif);
14136c92544dSBjoern A. Zeeb }
14146c92544dSBjoern A. Zeeb
mt7921_switch_vif_chanctx(struct ieee80211_hw * hw,struct ieee80211_vif_chanctx_switch * vifs,int n_vifs,enum ieee80211_chanctx_switch_mode mode)1415*8ba4d145SBjoern A. Zeeb static int mt7921_switch_vif_chanctx(struct ieee80211_hw *hw,
1416*8ba4d145SBjoern A. Zeeb struct ieee80211_vif_chanctx_switch *vifs,
1417*8ba4d145SBjoern A. Zeeb int n_vifs,
1418*8ba4d145SBjoern A. Zeeb enum ieee80211_chanctx_switch_mode mode)
1419*8ba4d145SBjoern A. Zeeb {
1420*8ba4d145SBjoern A. Zeeb return mt792x_assign_vif_chanctx(hw, vifs->vif, vifs->link_conf,
1421*8ba4d145SBjoern A. Zeeb vifs->new_ctx);
1422*8ba4d145SBjoern A. Zeeb }
1423*8ba4d145SBjoern A. Zeeb
mt7921_csa_work(struct work_struct * work)1424*8ba4d145SBjoern A. Zeeb void mt7921_csa_work(struct work_struct *work)
1425*8ba4d145SBjoern A. Zeeb {
1426*8ba4d145SBjoern A. Zeeb struct mt792x_vif *mvif;
1427*8ba4d145SBjoern A. Zeeb struct mt792x_dev *dev;
1428*8ba4d145SBjoern A. Zeeb struct ieee80211_vif *vif;
1429*8ba4d145SBjoern A. Zeeb int ret;
1430*8ba4d145SBjoern A. Zeeb
1431*8ba4d145SBjoern A. Zeeb mvif = (struct mt792x_vif *)container_of(work, struct mt792x_vif,
1432*8ba4d145SBjoern A. Zeeb csa_work);
1433*8ba4d145SBjoern A. Zeeb dev = mvif->phy->dev;
1434*8ba4d145SBjoern A. Zeeb vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv);
1435*8ba4d145SBjoern A. Zeeb
1436*8ba4d145SBjoern A. Zeeb mt792x_mutex_acquire(dev);
1437*8ba4d145SBjoern A. Zeeb ret = mt76_connac_mcu_uni_set_chctx(mvif->phy->mt76, &mvif->bss_conf.mt76,
1438*8ba4d145SBjoern A. Zeeb dev->new_ctx);
1439*8ba4d145SBjoern A. Zeeb mt792x_mutex_release(dev);
1440*8ba4d145SBjoern A. Zeeb
1441*8ba4d145SBjoern A. Zeeb ieee80211_chswitch_done(vif, !ret, 0);
1442*8ba4d145SBjoern A. Zeeb }
1443*8ba4d145SBjoern A. Zeeb
mt7921_pre_channel_switch(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_channel_switch * chsw)1444*8ba4d145SBjoern A. Zeeb static int mt7921_pre_channel_switch(struct ieee80211_hw *hw,
1445*8ba4d145SBjoern A. Zeeb struct ieee80211_vif *vif,
1446*8ba4d145SBjoern A. Zeeb struct ieee80211_channel_switch *chsw)
1447*8ba4d145SBjoern A. Zeeb {
1448*8ba4d145SBjoern A. Zeeb if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc)
1449*8ba4d145SBjoern A. Zeeb return -EOPNOTSUPP;
1450*8ba4d145SBjoern A. Zeeb
1451*8ba4d145SBjoern A. Zeeb /* Avoid beacon loss due to the CAC(Channel Availability Check) time
1452*8ba4d145SBjoern A. Zeeb * of the AP.
1453*8ba4d145SBjoern A. Zeeb */
1454*8ba4d145SBjoern A. Zeeb if (!cfg80211_chandef_usable(hw->wiphy, &chsw->chandef,
1455*8ba4d145SBjoern A. Zeeb IEEE80211_CHAN_RADAR))
1456*8ba4d145SBjoern A. Zeeb return -EOPNOTSUPP;
1457*8ba4d145SBjoern A. Zeeb
1458*8ba4d145SBjoern A. Zeeb return 0;
1459*8ba4d145SBjoern A. Zeeb }
1460*8ba4d145SBjoern A. Zeeb
mt7921_channel_switch(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_channel_switch * chsw)1461*8ba4d145SBjoern A. Zeeb static void mt7921_channel_switch(struct ieee80211_hw *hw,
1462*8ba4d145SBjoern A. Zeeb struct ieee80211_vif *vif,
1463*8ba4d145SBjoern A. Zeeb struct ieee80211_channel_switch *chsw)
1464*8ba4d145SBjoern A. Zeeb {
1465*8ba4d145SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1466*8ba4d145SBjoern A. Zeeb u16 beacon_interval = vif->bss_conf.beacon_int;
1467*8ba4d145SBjoern A. Zeeb
1468*8ba4d145SBjoern A. Zeeb mvif->csa_timer.expires = TU_TO_EXP_TIME(beacon_interval * chsw->count);
1469*8ba4d145SBjoern A. Zeeb add_timer(&mvif->csa_timer);
1470*8ba4d145SBjoern A. Zeeb }
1471*8ba4d145SBjoern A. Zeeb
mt7921_abort_channel_switch(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)1472*8ba4d145SBjoern A. Zeeb static void mt7921_abort_channel_switch(struct ieee80211_hw *hw,
1473*8ba4d145SBjoern A. Zeeb struct ieee80211_vif *vif,
1474*8ba4d145SBjoern A. Zeeb struct ieee80211_bss_conf *link_conf)
1475*8ba4d145SBjoern A. Zeeb {
1476*8ba4d145SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1477*8ba4d145SBjoern A. Zeeb
1478*8ba4d145SBjoern A. Zeeb del_timer_sync(&mvif->csa_timer);
1479*8ba4d145SBjoern A. Zeeb cancel_work_sync(&mvif->csa_work);
1480*8ba4d145SBjoern A. Zeeb }
1481*8ba4d145SBjoern A. Zeeb
mt7921_channel_switch_rx_beacon(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_channel_switch * chsw)1482*8ba4d145SBjoern A. Zeeb static void mt7921_channel_switch_rx_beacon(struct ieee80211_hw *hw,
1483*8ba4d145SBjoern A. Zeeb struct ieee80211_vif *vif,
1484*8ba4d145SBjoern A. Zeeb struct ieee80211_channel_switch *chsw)
1485*8ba4d145SBjoern A. Zeeb {
1486*8ba4d145SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
1487*8ba4d145SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1488*8ba4d145SBjoern A. Zeeb u16 beacon_interval = vif->bss_conf.beacon_int;
1489*8ba4d145SBjoern A. Zeeb
1490*8ba4d145SBjoern A. Zeeb if (cfg80211_chandef_identical(&chsw->chandef,
1491*8ba4d145SBjoern A. Zeeb &dev->new_ctx->def) &&
1492*8ba4d145SBjoern A. Zeeb chsw->count) {
1493*8ba4d145SBjoern A. Zeeb mod_timer(&mvif->csa_timer,
1494*8ba4d145SBjoern A. Zeeb TU_TO_EXP_TIME(beacon_interval * chsw->count));
1495*8ba4d145SBjoern A. Zeeb }
1496*8ba4d145SBjoern A. Zeeb }
1497*8ba4d145SBjoern A. Zeeb
mt7921_rfkill_poll(struct ieee80211_hw * hw)1498*8ba4d145SBjoern A. Zeeb static void mt7921_rfkill_poll(struct ieee80211_hw *hw)
1499*8ba4d145SBjoern A. Zeeb {
1500*8ba4d145SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
1501*8ba4d145SBjoern A. Zeeb int ret = 0;
1502*8ba4d145SBjoern A. Zeeb
1503*8ba4d145SBjoern A. Zeeb mt792x_mutex_acquire(phy->dev);
1504*8ba4d145SBjoern A. Zeeb ret = mt7921_mcu_wf_rf_pin_ctrl(phy, WF_RF_PIN_POLL);
1505*8ba4d145SBjoern A. Zeeb mt792x_mutex_release(phy->dev);
1506*8ba4d145SBjoern A. Zeeb
1507*8ba4d145SBjoern A. Zeeb wiphy_rfkill_set_hw_state(hw->wiphy, ret ? false : true);
1508*8ba4d145SBjoern A. Zeeb }
1509*8ba4d145SBjoern A. Zeeb
15106c92544dSBjoern A. Zeeb const struct ieee80211_ops mt7921_ops = {
1511cbb3ec25SBjoern A. Zeeb .tx = mt792x_tx,
15126c92544dSBjoern A. Zeeb .start = mt7921_start,
15136c92544dSBjoern A. Zeeb .stop = mt7921_stop,
15146c92544dSBjoern A. Zeeb .add_interface = mt7921_add_interface,
1515cbb3ec25SBjoern A. Zeeb .remove_interface = mt792x_remove_interface,
15166c92544dSBjoern A. Zeeb .config = mt7921_config,
1517cbb3ec25SBjoern A. Zeeb .conf_tx = mt792x_conf_tx,
15186c92544dSBjoern A. Zeeb .configure_filter = mt7921_configure_filter,
15196c92544dSBjoern A. Zeeb .bss_info_changed = mt7921_bss_info_changed,
15206c92544dSBjoern A. Zeeb .start_ap = mt7921_start_ap,
15216c92544dSBjoern A. Zeeb .stop_ap = mt7921_stop_ap,
15226c92544dSBjoern A. Zeeb .sta_state = mt7921_sta_state,
15236c92544dSBjoern A. Zeeb .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
15246c92544dSBjoern A. Zeeb .set_key = mt7921_set_key,
15256c92544dSBjoern A. Zeeb .sta_set_decap_offload = mt7921_sta_set_decap_offload,
15266c92544dSBjoern A. Zeeb #if IS_ENABLED(CONFIG_IPV6)
15276c92544dSBjoern A. Zeeb .ipv6_addr_change = mt7921_ipv6_addr_change,
15286c92544dSBjoern A. Zeeb #endif /* CONFIG_IPV6 */
15296c92544dSBjoern A. Zeeb .ampdu_action = mt7921_ampdu_action,
15306c92544dSBjoern A. Zeeb .set_rts_threshold = mt7921_set_rts_threshold,
15316c92544dSBjoern A. Zeeb .wake_tx_queue = mt76_wake_tx_queue,
15326c92544dSBjoern A. Zeeb .release_buffered_frames = mt76_release_buffered_frames,
15336c92544dSBjoern A. Zeeb .channel_switch_beacon = mt7921_channel_switch_beacon,
15346c92544dSBjoern A. Zeeb .get_txpower = mt76_get_txpower,
1535cbb3ec25SBjoern A. Zeeb .get_stats = mt792x_get_stats,
1536cbb3ec25SBjoern A. Zeeb .get_et_sset_count = mt792x_get_et_sset_count,
1537cbb3ec25SBjoern A. Zeeb .get_et_strings = mt792x_get_et_strings,
1538cbb3ec25SBjoern A. Zeeb .get_et_stats = mt792x_get_et_stats,
1539cbb3ec25SBjoern A. Zeeb .get_tsf = mt792x_get_tsf,
1540cbb3ec25SBjoern A. Zeeb .set_tsf = mt792x_set_tsf,
15416c92544dSBjoern A. Zeeb .get_survey = mt76_get_survey,
15426c92544dSBjoern A. Zeeb .get_antenna = mt76_get_antenna,
15436c92544dSBjoern A. Zeeb .set_antenna = mt7921_set_antenna,
1544cbb3ec25SBjoern A. Zeeb .set_coverage_class = mt792x_set_coverage_class,
15456c92544dSBjoern A. Zeeb .hw_scan = mt7921_hw_scan,
15466c92544dSBjoern A. Zeeb .cancel_hw_scan = mt7921_cancel_hw_scan,
1547cbb3ec25SBjoern A. Zeeb .sta_statistics = mt792x_sta_statistics,
15486c92544dSBjoern A. Zeeb .sched_scan_start = mt7921_start_sched_scan,
15496c92544dSBjoern A. Zeeb .sched_scan_stop = mt7921_stop_sched_scan,
15506c92544dSBjoern A. Zeeb CFG80211_TESTMODE_CMD(mt7921_testmode_cmd)
15516c92544dSBjoern A. Zeeb CFG80211_TESTMODE_DUMP(mt7921_testmode_dump)
15526c92544dSBjoern A. Zeeb #ifdef CONFIG_PM
15536c92544dSBjoern A. Zeeb .suspend = mt7921_suspend,
15546c92544dSBjoern A. Zeeb .resume = mt7921_resume,
1555cbb3ec25SBjoern A. Zeeb .set_wakeup = mt792x_set_wakeup,
15566c92544dSBjoern A. Zeeb .set_rekey_data = mt7921_set_rekey_data,
15576c92544dSBjoern A. Zeeb #endif /* CONFIG_PM */
1558cbb3ec25SBjoern A. Zeeb .flush = mt792x_flush,
15596c92544dSBjoern A. Zeeb .set_sar_specs = mt7921_set_sar_specs,
1560*8ba4d145SBjoern A. Zeeb .rfkill_poll = mt7921_rfkill_poll,
1561cbb3ec25SBjoern A. Zeeb .remain_on_channel = mt7921_remain_on_channel,
1562cbb3ec25SBjoern A. Zeeb .cancel_remain_on_channel = mt7921_cancel_remain_on_channel,
1563cbb3ec25SBjoern A. Zeeb .add_chanctx = mt7921_add_chanctx,
1564cbb3ec25SBjoern A. Zeeb .remove_chanctx = mt7921_remove_chanctx,
1565cbb3ec25SBjoern A. Zeeb .change_chanctx = mt7921_change_chanctx,
1566cbb3ec25SBjoern A. Zeeb .assign_vif_chanctx = mt792x_assign_vif_chanctx,
1567cbb3ec25SBjoern A. Zeeb .unassign_vif_chanctx = mt792x_unassign_vif_chanctx,
1568cbb3ec25SBjoern A. Zeeb .mgd_prepare_tx = mt7921_mgd_prepare_tx,
1569cbb3ec25SBjoern A. Zeeb .mgd_complete_tx = mt7921_mgd_complete_tx,
1570*8ba4d145SBjoern A. Zeeb .switch_vif_chanctx = mt7921_switch_vif_chanctx,
1571*8ba4d145SBjoern A. Zeeb .pre_channel_switch = mt7921_pre_channel_switch,
1572*8ba4d145SBjoern A. Zeeb .channel_switch = mt7921_channel_switch,
1573*8ba4d145SBjoern A. Zeeb .abort_channel_switch = mt7921_abort_channel_switch,
1574*8ba4d145SBjoern A. Zeeb .channel_switch_rx_beacon = mt7921_channel_switch_rx_beacon,
15756c92544dSBjoern A. Zeeb };
15766c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt7921_ops);
15776c92544dSBjoern A. Zeeb
1578*8ba4d145SBjoern A. Zeeb MODULE_DESCRIPTION("MediaTek MT7921 core driver");
15796c92544dSBjoern A. Zeeb MODULE_LICENSE("Dual BSD/GPL");
15806c92544dSBjoern A. Zeeb MODULE_AUTHOR("Sean Wang <sean.wang@mediatek.com>");
1581