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)13*cbb3ec25SBjoern 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*cbb3ec25SBjoern A. Zeeb mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss);
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)188*cbb3ec25SBjoern 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;
1996c92544dSBjoern A. Zeeb band->iftype_data = data;
2006c92544dSBjoern A. Zeeb band->n_iftype_data = n;
2016c92544dSBjoern A. Zeeb }
2026c92544dSBjoern A. Zeeb
2036c92544dSBjoern A. Zeeb if (phy->mt76->cap.has_5ghz) {
2046c92544dSBjoern A. Zeeb data = phy->iftype[NL80211_BAND_5GHZ];
2056c92544dSBjoern A. Zeeb n = mt7921_init_he_caps(phy, NL80211_BAND_5GHZ, data);
2066c92544dSBjoern A. Zeeb
2076c92544dSBjoern A. Zeeb band = &phy->mt76->sband_5g.sband;
2086c92544dSBjoern A. Zeeb band->iftype_data = data;
2096c92544dSBjoern A. Zeeb band->n_iftype_data = n;
2106c92544dSBjoern A. Zeeb
2116c92544dSBjoern A. Zeeb if (phy->mt76->cap.has_6ghz) {
2126c92544dSBjoern A. Zeeb data = phy->iftype[NL80211_BAND_6GHZ];
2136c92544dSBjoern A. Zeeb n = mt7921_init_he_caps(phy, NL80211_BAND_6GHZ, data);
2146c92544dSBjoern A. Zeeb
2156c92544dSBjoern A. Zeeb band = &phy->mt76->sband_6g.sband;
2166c92544dSBjoern A. Zeeb band->iftype_data = data;
2176c92544dSBjoern A. Zeeb band->n_iftype_data = n;
2186c92544dSBjoern A. Zeeb }
2196c92544dSBjoern A. Zeeb }
2206c92544dSBjoern A. Zeeb }
2216c92544dSBjoern A. Zeeb
__mt7921_start(struct mt792x_phy * phy)222*cbb3ec25SBjoern A. Zeeb int __mt7921_start(struct mt792x_phy *phy)
2236c92544dSBjoern A. Zeeb {
2246c92544dSBjoern A. Zeeb struct mt76_phy *mphy = phy->mt76;
2256c92544dSBjoern A. Zeeb int err;
2266c92544dSBjoern A. Zeeb
2276c92544dSBjoern A. Zeeb err = mt76_connac_mcu_set_mac_enable(mphy->dev, 0, true, false);
2286c92544dSBjoern A. Zeeb if (err)
2296c92544dSBjoern A. Zeeb return err;
2306c92544dSBjoern A. Zeeb
2316c92544dSBjoern A. Zeeb err = mt76_connac_mcu_set_channel_domain(mphy);
2326c92544dSBjoern A. Zeeb if (err)
2336c92544dSBjoern A. Zeeb return err;
2346c92544dSBjoern A. Zeeb
2356c92544dSBjoern A. Zeeb err = mt7921_mcu_set_chan_info(phy, MCU_EXT_CMD(SET_RX_PATH));
2366c92544dSBjoern A. Zeeb if (err)
2376c92544dSBjoern A. Zeeb return err;
2386c92544dSBjoern A. Zeeb
2396c92544dSBjoern A. Zeeb err = mt7921_set_tx_sar_pwr(mphy->hw, NULL);
2406c92544dSBjoern A. Zeeb if (err)
2416c92544dSBjoern A. Zeeb return err;
2426c92544dSBjoern A. Zeeb
243*cbb3ec25SBjoern A. Zeeb mt792x_mac_reset_counters(phy);
2446c92544dSBjoern A. Zeeb set_bit(MT76_STATE_RUNNING, &mphy->state);
2456c92544dSBjoern A. Zeeb
2466c92544dSBjoern A. Zeeb ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
247*cbb3ec25SBjoern A. Zeeb MT792x_WATCHDOG_TIME);
2486c92544dSBjoern A. Zeeb
2496c92544dSBjoern A. Zeeb return 0;
2506c92544dSBjoern A. Zeeb }
2516c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(__mt7921_start);
2526c92544dSBjoern A. Zeeb
mt7921_start(struct ieee80211_hw * hw)2536c92544dSBjoern A. Zeeb static int mt7921_start(struct ieee80211_hw *hw)
2546c92544dSBjoern A. Zeeb {
255*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
2566c92544dSBjoern A. Zeeb int err;
2576c92544dSBjoern A. Zeeb
258*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(phy->dev);
2596c92544dSBjoern A. Zeeb err = __mt7921_start(phy);
260*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(phy->dev);
2616c92544dSBjoern A. Zeeb
2626c92544dSBjoern A. Zeeb return err;
2636c92544dSBjoern A. Zeeb }
2646c92544dSBjoern A. Zeeb
mt7921_stop(struct ieee80211_hw * hw)2656c92544dSBjoern A. Zeeb void mt7921_stop(struct ieee80211_hw *hw)
2666c92544dSBjoern A. Zeeb {
267*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
268*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
2696c92544dSBjoern A. Zeeb
2706c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&phy->mt76->mac_work);
2716c92544dSBjoern A. Zeeb
2726c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&dev->pm.ps_work);
2736c92544dSBjoern A. Zeeb cancel_work_sync(&dev->pm.wake_work);
2746c92544dSBjoern A. Zeeb cancel_work_sync(&dev->reset_work);
2756c92544dSBjoern A. Zeeb mt76_connac_free_pending_tx_skbs(&dev->pm, NULL);
2766c92544dSBjoern A. Zeeb
277*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
2786c92544dSBjoern A. Zeeb clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
2796c92544dSBjoern A. Zeeb mt76_connac_mcu_set_mac_enable(&dev->mt76, 0, false, false);
280*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
2816c92544dSBjoern A. Zeeb }
2826c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt7921_stop);
2836c92544dSBjoern A. Zeeb
284*cbb3ec25SBjoern A. Zeeb static int
mt7921_add_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)285*cbb3ec25SBjoern A. Zeeb mt7921_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2866c92544dSBjoern A. Zeeb {
287*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
288*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
289*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
2906c92544dSBjoern A. Zeeb struct mt76_txq *mtxq;
2916c92544dSBjoern A. Zeeb int idx, ret = 0;
2926c92544dSBjoern A. Zeeb
293*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
2946c92544dSBjoern A. Zeeb
2956c92544dSBjoern A. Zeeb mvif->mt76.idx = __ffs64(~dev->mt76.vif_mask);
296*cbb3ec25SBjoern A. Zeeb if (mvif->mt76.idx >= MT792x_MAX_INTERFACES) {
2976c92544dSBjoern A. Zeeb ret = -ENOSPC;
2986c92544dSBjoern A. Zeeb goto out;
2996c92544dSBjoern A. Zeeb }
3006c92544dSBjoern A. Zeeb
3016c92544dSBjoern A. Zeeb mvif->mt76.omac_idx = mvif->mt76.idx;
3026c92544dSBjoern A. Zeeb mvif->phy = phy;
3036c92544dSBjoern A. Zeeb mvif->mt76.band_idx = 0;
3046c92544dSBjoern A. Zeeb mvif->mt76.wmm_idx = mvif->mt76.idx % MT76_CONNAC_MAX_WMM_SETS;
3056c92544dSBjoern A. Zeeb
3066c92544dSBjoern A. Zeeb ret = mt76_connac_mcu_uni_add_dev(&dev->mphy, vif, &mvif->sta.wcid,
3076c92544dSBjoern A. Zeeb true);
3086c92544dSBjoern A. Zeeb if (ret)
3096c92544dSBjoern A. Zeeb goto out;
3106c92544dSBjoern A. Zeeb
3116c92544dSBjoern A. Zeeb dev->mt76.vif_mask |= BIT_ULL(mvif->mt76.idx);
3126c92544dSBjoern A. Zeeb phy->omac_mask |= BIT_ULL(mvif->mt76.omac_idx);
3136c92544dSBjoern A. Zeeb
314*cbb3ec25SBjoern A. Zeeb idx = MT792x_WTBL_RESERVED - mvif->mt76.idx;
3156c92544dSBjoern A. Zeeb
316*cbb3ec25SBjoern A. Zeeb INIT_LIST_HEAD(&mvif->sta.wcid.poll_list);
3176c92544dSBjoern A. Zeeb mvif->sta.wcid.idx = idx;
3186c92544dSBjoern A. Zeeb mvif->sta.wcid.phy_idx = mvif->mt76.band_idx;
3196c92544dSBjoern A. Zeeb mvif->sta.wcid.hw_key_idx = -1;
3206c92544dSBjoern A. Zeeb mvif->sta.wcid.tx_info |= MT_WCID_TX_INFO_SET;
3216c92544dSBjoern A. Zeeb mt76_packet_id_init(&mvif->sta.wcid);
3226c92544dSBjoern A. Zeeb
3236c92544dSBjoern A. Zeeb mt7921_mac_wtbl_update(dev, idx,
3246c92544dSBjoern A. Zeeb MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
3256c92544dSBjoern A. Zeeb
3266c92544dSBjoern A. Zeeb ewma_rssi_init(&mvif->rssi);
3276c92544dSBjoern A. Zeeb
3286c92544dSBjoern A. Zeeb rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid);
3296c92544dSBjoern A. Zeeb if (vif->txq) {
3306c92544dSBjoern A. Zeeb mtxq = (struct mt76_txq *)vif->txq->drv_priv;
3316c92544dSBjoern A. Zeeb mtxq->wcid = idx;
3326c92544dSBjoern A. Zeeb }
3336c92544dSBjoern A. Zeeb
3346c92544dSBjoern A. Zeeb vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
3356c92544dSBjoern A. Zeeb out:
336*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
3376c92544dSBjoern A. Zeeb
3386c92544dSBjoern A. Zeeb return ret;
3396c92544dSBjoern A. Zeeb }
3406c92544dSBjoern A. Zeeb
mt7921_roc_iter(void * priv,u8 * mac,struct ieee80211_vif * vif)341*cbb3ec25SBjoern A. Zeeb static void mt7921_roc_iter(void *priv, u8 *mac,
3426c92544dSBjoern A. Zeeb struct ieee80211_vif *vif)
3436c92544dSBjoern A. Zeeb {
344*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
345*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = priv;
3466c92544dSBjoern A. Zeeb
347*cbb3ec25SBjoern A. Zeeb mt7921_mcu_abort_roc(phy, mvif, phy->roc_token_id);
3486c92544dSBjoern A. Zeeb }
3496c92544dSBjoern A. Zeeb
mt7921_roc_work(struct work_struct * work)350*cbb3ec25SBjoern A. Zeeb void mt7921_roc_work(struct work_struct *work)
3516c92544dSBjoern A. Zeeb {
352*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy;
353*cbb3ec25SBjoern A. Zeeb
354*cbb3ec25SBjoern A. Zeeb phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy,
355*cbb3ec25SBjoern A. Zeeb roc_work);
356*cbb3ec25SBjoern A. Zeeb
357*cbb3ec25SBjoern A. Zeeb if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
358*cbb3ec25SBjoern A. Zeeb return;
359*cbb3ec25SBjoern A. Zeeb
360*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(phy->dev);
361*cbb3ec25SBjoern A. Zeeb ieee80211_iterate_active_interfaces(phy->mt76->hw,
362*cbb3ec25SBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL,
363*cbb3ec25SBjoern A. Zeeb mt7921_roc_iter, phy);
364*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(phy->dev);
365*cbb3ec25SBjoern A. Zeeb ieee80211_remain_on_channel_expired(phy->mt76->hw);
366*cbb3ec25SBjoern A. Zeeb }
367*cbb3ec25SBjoern A. Zeeb
mt7921_abort_roc(struct mt792x_phy * phy,struct mt792x_vif * vif)368*cbb3ec25SBjoern A. Zeeb static int mt7921_abort_roc(struct mt792x_phy *phy, struct mt792x_vif *vif)
369*cbb3ec25SBjoern A. Zeeb {
370*cbb3ec25SBjoern A. Zeeb int err = 0;
371*cbb3ec25SBjoern A. Zeeb
372*cbb3ec25SBjoern A. Zeeb del_timer_sync(&phy->roc_timer);
373*cbb3ec25SBjoern A. Zeeb cancel_work_sync(&phy->roc_work);
374*cbb3ec25SBjoern A. Zeeb
375*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(phy->dev);
376*cbb3ec25SBjoern A. Zeeb if (test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
377*cbb3ec25SBjoern A. Zeeb err = mt7921_mcu_abort_roc(phy, vif, phy->roc_token_id);
378*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(phy->dev);
379*cbb3ec25SBjoern A. Zeeb
380*cbb3ec25SBjoern A. Zeeb return err;
381*cbb3ec25SBjoern A. Zeeb }
382*cbb3ec25SBjoern A. Zeeb
mt7921_set_roc(struct mt792x_phy * phy,struct mt792x_vif * vif,struct ieee80211_channel * chan,int duration,enum mt7921_roc_req type)383*cbb3ec25SBjoern A. Zeeb static int mt7921_set_roc(struct mt792x_phy *phy,
384*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *vif,
385*cbb3ec25SBjoern A. Zeeb struct ieee80211_channel *chan,
386*cbb3ec25SBjoern A. Zeeb int duration,
387*cbb3ec25SBjoern A. Zeeb enum mt7921_roc_req type)
388*cbb3ec25SBjoern A. Zeeb {
389*cbb3ec25SBjoern A. Zeeb int err;
390*cbb3ec25SBjoern A. Zeeb
391*cbb3ec25SBjoern A. Zeeb if (test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state))
392*cbb3ec25SBjoern A. Zeeb return -EBUSY;
393*cbb3ec25SBjoern A. Zeeb
394*cbb3ec25SBjoern A. Zeeb phy->roc_grant = false;
395*cbb3ec25SBjoern A. Zeeb
396*cbb3ec25SBjoern A. Zeeb err = mt7921_mcu_set_roc(phy, vif, chan, duration, type,
397*cbb3ec25SBjoern A. Zeeb ++phy->roc_token_id);
398*cbb3ec25SBjoern A. Zeeb if (err < 0) {
399*cbb3ec25SBjoern A. Zeeb clear_bit(MT76_STATE_ROC, &phy->mt76->state);
400*cbb3ec25SBjoern A. Zeeb goto out;
401*cbb3ec25SBjoern A. Zeeb }
402*cbb3ec25SBjoern A. Zeeb
403*cbb3ec25SBjoern A. Zeeb if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, HZ)) {
404*cbb3ec25SBjoern A. Zeeb mt7921_mcu_abort_roc(phy, vif, phy->roc_token_id);
405*cbb3ec25SBjoern A. Zeeb clear_bit(MT76_STATE_ROC, &phy->mt76->state);
406*cbb3ec25SBjoern A. Zeeb err = -ETIMEDOUT;
407*cbb3ec25SBjoern A. Zeeb }
408*cbb3ec25SBjoern A. Zeeb
409*cbb3ec25SBjoern A. Zeeb out:
410*cbb3ec25SBjoern A. Zeeb return err;
411*cbb3ec25SBjoern A. Zeeb }
412*cbb3ec25SBjoern 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)413*cbb3ec25SBjoern A. Zeeb static int mt7921_remain_on_channel(struct ieee80211_hw *hw,
414*cbb3ec25SBjoern A. Zeeb struct ieee80211_vif *vif,
415*cbb3ec25SBjoern A. Zeeb struct ieee80211_channel *chan,
416*cbb3ec25SBjoern A. Zeeb int duration,
417*cbb3ec25SBjoern A. Zeeb enum ieee80211_roc_type type)
418*cbb3ec25SBjoern A. Zeeb {
419*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
420*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
421*cbb3ec25SBjoern A. Zeeb int err;
422*cbb3ec25SBjoern A. Zeeb
423*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(phy->dev);
424*cbb3ec25SBjoern A. Zeeb err = mt7921_set_roc(phy, mvif, chan, duration, MT7921_ROC_REQ_ROC);
425*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(phy->dev);
426*cbb3ec25SBjoern A. Zeeb
427*cbb3ec25SBjoern A. Zeeb return err;
428*cbb3ec25SBjoern A. Zeeb }
429*cbb3ec25SBjoern A. Zeeb
mt7921_cancel_remain_on_channel(struct ieee80211_hw * hw,struct ieee80211_vif * vif)430*cbb3ec25SBjoern A. Zeeb static int mt7921_cancel_remain_on_channel(struct ieee80211_hw *hw,
431*cbb3ec25SBjoern A. Zeeb struct ieee80211_vif *vif)
432*cbb3ec25SBjoern A. Zeeb {
433*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
434*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
435*cbb3ec25SBjoern A. Zeeb
436*cbb3ec25SBjoern A. Zeeb return mt7921_abort_roc(phy, mvif);
437*cbb3ec25SBjoern A. Zeeb }
438*cbb3ec25SBjoern A. Zeeb
mt7921_set_channel(struct mt792x_phy * phy)439*cbb3ec25SBjoern A. Zeeb static int mt7921_set_channel(struct mt792x_phy *phy)
440*cbb3ec25SBjoern A. Zeeb {
441*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = phy->dev;
4426c92544dSBjoern A. Zeeb int ret;
4436c92544dSBjoern A. Zeeb
4446c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&phy->mt76->mac_work);
4456c92544dSBjoern A. Zeeb
446*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
4476c92544dSBjoern A. Zeeb set_bit(MT76_RESET, &phy->mt76->state);
4486c92544dSBjoern A. Zeeb
4496c92544dSBjoern A. Zeeb mt76_set_channel(phy->mt76);
4506c92544dSBjoern A. Zeeb
4516c92544dSBjoern A. Zeeb ret = mt7921_mcu_set_chan_info(phy, MCU_EXT_CMD(CHANNEL_SWITCH));
4526c92544dSBjoern A. Zeeb if (ret)
4536c92544dSBjoern A. Zeeb goto out;
4546c92544dSBjoern A. Zeeb
455*cbb3ec25SBjoern A. Zeeb mt792x_mac_set_timeing(phy);
4566c92544dSBjoern A. Zeeb
457*cbb3ec25SBjoern A. Zeeb mt792x_mac_reset_counters(phy);
4586c92544dSBjoern A. Zeeb phy->noise = 0;
4596c92544dSBjoern A. Zeeb
4606c92544dSBjoern A. Zeeb out:
4616c92544dSBjoern A. Zeeb clear_bit(MT76_RESET, &phy->mt76->state);
462*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
4636c92544dSBjoern A. Zeeb
4646c92544dSBjoern A. Zeeb mt76_worker_schedule(&dev->mt76.tx_worker);
4656c92544dSBjoern A. Zeeb ieee80211_queue_delayed_work(phy->mt76->hw, &phy->mt76->mac_work,
466*cbb3ec25SBjoern A. Zeeb MT792x_WATCHDOG_TIME);
4676c92544dSBjoern A. Zeeb
4686c92544dSBjoern A. Zeeb return ret;
4696c92544dSBjoern A. Zeeb }
4706c92544dSBjoern 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)4716c92544dSBjoern A. Zeeb static int mt7921_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4726c92544dSBjoern A. Zeeb struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4736c92544dSBjoern A. Zeeb struct ieee80211_key_conf *key)
4746c92544dSBjoern A. Zeeb {
475*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
476*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
477*cbb3ec25SBjoern A. Zeeb struct mt792x_sta *msta = sta ? (struct mt792x_sta *)sta->drv_priv :
4786c92544dSBjoern A. Zeeb &mvif->sta;
4796c92544dSBjoern A. Zeeb struct mt76_wcid *wcid = &msta->wcid;
4806c92544dSBjoern A. Zeeb u8 *wcid_keyidx = &wcid->hw_key_idx;
4816c92544dSBjoern A. Zeeb int idx = key->keyidx, err = 0;
4826c92544dSBjoern A. Zeeb
4836c92544dSBjoern A. Zeeb /* The hardware does not support per-STA RX GTK, fallback
4846c92544dSBjoern A. Zeeb * to software mode for these.
4856c92544dSBjoern A. Zeeb */
4866c92544dSBjoern A. Zeeb if ((vif->type == NL80211_IFTYPE_ADHOC ||
4876c92544dSBjoern A. Zeeb vif->type == NL80211_IFTYPE_MESH_POINT) &&
4886c92544dSBjoern A. Zeeb (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
4896c92544dSBjoern A. Zeeb key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
4906c92544dSBjoern A. Zeeb !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
4916c92544dSBjoern A. Zeeb return -EOPNOTSUPP;
4926c92544dSBjoern A. Zeeb
4936c92544dSBjoern A. Zeeb /* fall back to sw encryption for unsupported ciphers */
4946c92544dSBjoern A. Zeeb switch (key->cipher) {
4956c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC:
4966c92544dSBjoern A. Zeeb key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
4976c92544dSBjoern A. Zeeb wcid_keyidx = &wcid->hw_key_idx2;
4986c92544dSBjoern A. Zeeb break;
4996c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40:
5006c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104:
5016c92544dSBjoern A. Zeeb if (!mvif->wep_sta)
5026c92544dSBjoern A. Zeeb return -EOPNOTSUPP;
5036c92544dSBjoern A. Zeeb break;
5046c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP:
5056c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP:
5066c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256:
5076c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP:
5086c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256:
5096c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_SMS4:
5106c92544dSBjoern A. Zeeb break;
5116c92544dSBjoern A. Zeeb default:
5126c92544dSBjoern A. Zeeb return -EOPNOTSUPP;
5136c92544dSBjoern A. Zeeb }
5146c92544dSBjoern A. Zeeb
515*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
5166c92544dSBjoern A. Zeeb
517*cbb3ec25SBjoern A. Zeeb if (cmd == SET_KEY) {
5186c92544dSBjoern A. Zeeb *wcid_keyidx = idx;
519*cbb3ec25SBjoern A. Zeeb } else {
520*cbb3ec25SBjoern A. Zeeb if (idx == *wcid_keyidx)
5216c92544dSBjoern A. Zeeb *wcid_keyidx = -1;
5226c92544dSBjoern A. Zeeb goto out;
523*cbb3ec25SBjoern A. Zeeb }
5246c92544dSBjoern A. Zeeb
525*cbb3ec25SBjoern A. Zeeb mt76_wcid_key_setup(&dev->mt76, wcid, key);
5266c92544dSBjoern A. Zeeb err = mt76_connac_mcu_add_key(&dev->mt76, vif, &msta->bip,
5276c92544dSBjoern A. Zeeb key, MCU_UNI_CMD(STA_REC_UPDATE),
5286c92544dSBjoern A. Zeeb &msta->wcid, cmd);
5296c92544dSBjoern A. Zeeb if (err)
5306c92544dSBjoern A. Zeeb goto out;
5316c92544dSBjoern A. Zeeb
5326c92544dSBjoern A. Zeeb if (key->cipher == WLAN_CIPHER_SUITE_WEP104 ||
5336c92544dSBjoern A. Zeeb key->cipher == WLAN_CIPHER_SUITE_WEP40)
5346c92544dSBjoern A. Zeeb err = mt76_connac_mcu_add_key(&dev->mt76, vif,
5356c92544dSBjoern A. Zeeb &mvif->wep_sta->bip,
5366c92544dSBjoern A. Zeeb key, MCU_UNI_CMD(STA_REC_UPDATE),
5376c92544dSBjoern A. Zeeb &mvif->wep_sta->wcid, cmd);
5386c92544dSBjoern A. Zeeb out:
539*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
5406c92544dSBjoern A. Zeeb
5416c92544dSBjoern A. Zeeb return err;
5426c92544dSBjoern A. Zeeb }
5436c92544dSBjoern A. Zeeb
5446c92544dSBjoern A. Zeeb static void
mt7921_pm_interface_iter(void * priv,u8 * mac,struct ieee80211_vif * vif)5456c92544dSBjoern A. Zeeb mt7921_pm_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
5466c92544dSBjoern A. Zeeb {
547*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = priv;
5486c92544dSBjoern A. Zeeb struct ieee80211_hw *hw = mt76_hw(dev);
5496c92544dSBjoern A. Zeeb bool pm_enable = dev->pm.enable;
5506c92544dSBjoern A. Zeeb int err;
5516c92544dSBjoern A. Zeeb
5526c92544dSBjoern A. Zeeb err = mt7921_mcu_set_beacon_filter(dev, vif, pm_enable);
5536c92544dSBjoern A. Zeeb if (err < 0)
5546c92544dSBjoern A. Zeeb return;
5556c92544dSBjoern A. Zeeb
5566c92544dSBjoern A. Zeeb if (pm_enable) {
5576c92544dSBjoern A. Zeeb vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
5586c92544dSBjoern A. Zeeb ieee80211_hw_set(hw, CONNECTION_MONITOR);
5596c92544dSBjoern A. Zeeb } else {
5606c92544dSBjoern A. Zeeb vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER;
5616c92544dSBjoern A. Zeeb __clear_bit(IEEE80211_HW_CONNECTION_MONITOR, hw->flags);
5626c92544dSBjoern A. Zeeb }
5636c92544dSBjoern A. Zeeb }
5646c92544dSBjoern A. Zeeb
5656c92544dSBjoern A. Zeeb static void
mt7921_sniffer_interface_iter(void * priv,u8 * mac,struct ieee80211_vif * vif)5666c92544dSBjoern A. Zeeb mt7921_sniffer_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
5676c92544dSBjoern A. Zeeb {
568*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = priv;
5696c92544dSBjoern A. Zeeb struct ieee80211_hw *hw = mt76_hw(dev);
5706c92544dSBjoern A. Zeeb struct mt76_connac_pm *pm = &dev->pm;
5716c92544dSBjoern A. Zeeb bool monitor = !!(hw->conf.flags & IEEE80211_CONF_MONITOR);
5726c92544dSBjoern A. Zeeb
5736c92544dSBjoern A. Zeeb mt7921_mcu_set_sniffer(dev, vif, monitor);
5746c92544dSBjoern A. Zeeb pm->enable = pm->enable_user && !monitor;
5756c92544dSBjoern A. Zeeb pm->ds_enable = pm->ds_enable_user && !monitor;
5766c92544dSBjoern A. Zeeb
5776c92544dSBjoern A. Zeeb mt76_connac_mcu_set_deep_sleep(&dev->mt76, pm->ds_enable);
5786c92544dSBjoern A. Zeeb
5796c92544dSBjoern A. Zeeb if (monitor)
5806c92544dSBjoern A. Zeeb mt7921_mcu_set_beacon_filter(dev, vif, false);
5816c92544dSBjoern A. Zeeb }
5826c92544dSBjoern A. Zeeb
mt7921_set_runtime_pm(struct mt792x_dev * dev)583*cbb3ec25SBjoern A. Zeeb void mt7921_set_runtime_pm(struct mt792x_dev *dev)
5846c92544dSBjoern A. Zeeb {
5856c92544dSBjoern A. Zeeb struct ieee80211_hw *hw = mt76_hw(dev);
5866c92544dSBjoern A. Zeeb struct mt76_connac_pm *pm = &dev->pm;
5876c92544dSBjoern A. Zeeb bool monitor = !!(hw->conf.flags & IEEE80211_CONF_MONITOR);
5886c92544dSBjoern A. Zeeb
5896c92544dSBjoern A. Zeeb pm->enable = pm->enable_user && !monitor;
5906c92544dSBjoern A. Zeeb ieee80211_iterate_active_interfaces(hw,
5916c92544dSBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL,
5926c92544dSBjoern A. Zeeb mt7921_pm_interface_iter, dev);
5936c92544dSBjoern A. Zeeb pm->ds_enable = pm->ds_enable_user && !monitor;
5946c92544dSBjoern A. Zeeb mt76_connac_mcu_set_deep_sleep(&dev->mt76, pm->ds_enable);
5956c92544dSBjoern A. Zeeb }
5966c92544dSBjoern A. Zeeb
mt7921_config(struct ieee80211_hw * hw,u32 changed)5976c92544dSBjoern A. Zeeb static int mt7921_config(struct ieee80211_hw *hw, u32 changed)
5986c92544dSBjoern A. Zeeb {
599*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
600*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
6016c92544dSBjoern A. Zeeb int ret = 0;
6026c92544dSBjoern A. Zeeb
6036c92544dSBjoern A. Zeeb if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
6046c92544dSBjoern A. Zeeb ieee80211_stop_queues(hw);
6056c92544dSBjoern A. Zeeb ret = mt7921_set_channel(phy);
6066c92544dSBjoern A. Zeeb if (ret)
6076c92544dSBjoern A. Zeeb return ret;
6086c92544dSBjoern A. Zeeb ieee80211_wake_queues(hw);
6096c92544dSBjoern A. Zeeb }
6106c92544dSBjoern A. Zeeb
611*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
6126c92544dSBjoern A. Zeeb
6136c92544dSBjoern A. Zeeb if (changed & IEEE80211_CONF_CHANGE_POWER) {
6146c92544dSBjoern A. Zeeb ret = mt7921_set_tx_sar_pwr(hw, NULL);
6156c92544dSBjoern A. Zeeb if (ret)
6166c92544dSBjoern A. Zeeb goto out;
6176c92544dSBjoern A. Zeeb }
6186c92544dSBjoern A. Zeeb
6196c92544dSBjoern A. Zeeb if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
6206c92544dSBjoern A. Zeeb ieee80211_iterate_active_interfaces(hw,
6216c92544dSBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL,
6226c92544dSBjoern A. Zeeb mt7921_sniffer_interface_iter, dev);
6236c92544dSBjoern A. Zeeb }
6246c92544dSBjoern A. Zeeb
6256c92544dSBjoern A. Zeeb out:
626*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
6276c92544dSBjoern A. Zeeb
6286c92544dSBjoern A. Zeeb return ret;
6296c92544dSBjoern A. Zeeb }
6306c92544dSBjoern A. Zeeb
mt7921_configure_filter(struct ieee80211_hw * hw,unsigned int changed_flags,unsigned int * total_flags,u64 multicast)6316c92544dSBjoern A. Zeeb static void mt7921_configure_filter(struct ieee80211_hw *hw,
6326c92544dSBjoern A. Zeeb unsigned int changed_flags,
6336c92544dSBjoern A. Zeeb unsigned int *total_flags,
6346c92544dSBjoern A. Zeeb u64 multicast)
6356c92544dSBjoern A. Zeeb {
636*cbb3ec25SBjoern A. Zeeb #define MT7921_FILTER_FCSFAIL BIT(2)
637*cbb3ec25SBjoern A. Zeeb #define MT7921_FILTER_CONTROL BIT(5)
638*cbb3ec25SBjoern A. Zeeb #define MT7921_FILTER_OTHER_BSS BIT(6)
639*cbb3ec25SBjoern A. Zeeb #define MT7921_FILTER_ENABLE BIT(31)
6406c92544dSBjoern A. Zeeb
641*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
642*cbb3ec25SBjoern A. Zeeb u32 flags = MT7921_FILTER_ENABLE;
643*cbb3ec25SBjoern A. Zeeb
644*cbb3ec25SBjoern A. Zeeb #define MT7921_FILTER(_fif, _type) do { \
645*cbb3ec25SBjoern A. Zeeb if (*total_flags & (_fif)) \
646*cbb3ec25SBjoern A. Zeeb flags |= MT7921_FILTER_##_type; \
6476c92544dSBjoern A. Zeeb } while (0)
6486c92544dSBjoern A. Zeeb
649*cbb3ec25SBjoern A. Zeeb MT7921_FILTER(FIF_FCSFAIL, FCSFAIL);
650*cbb3ec25SBjoern A. Zeeb MT7921_FILTER(FIF_CONTROL, CONTROL);
651*cbb3ec25SBjoern A. Zeeb MT7921_FILTER(FIF_OTHER_BSS, OTHER_BSS);
6526c92544dSBjoern A. Zeeb
653*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
654*cbb3ec25SBjoern A. Zeeb mt7921_mcu_set_rxfilter(dev, flags, 0, 0);
655*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
6566c92544dSBjoern A. Zeeb
657*cbb3ec25SBjoern A. Zeeb *total_flags &= (FIF_OTHER_BSS | FIF_FCSFAIL | FIF_CONTROL);
6586c92544dSBjoern A. Zeeb }
6596c92544dSBjoern A. Zeeb
mt7921_bss_info_changed(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * info,u64 changed)6606c92544dSBjoern A. Zeeb static void mt7921_bss_info_changed(struct ieee80211_hw *hw,
6616c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
6626c92544dSBjoern A. Zeeb struct ieee80211_bss_conf *info,
6636c92544dSBjoern A. Zeeb u64 changed)
6646c92544dSBjoern A. Zeeb {
665*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
666*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
6676c92544dSBjoern A. Zeeb
668*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
6696c92544dSBjoern A. Zeeb
6706c92544dSBjoern A. Zeeb if (changed & BSS_CHANGED_ERP_SLOT) {
6716c92544dSBjoern A. Zeeb int slottime = info->use_short_slot ? 9 : 20;
6726c92544dSBjoern A. Zeeb
6736c92544dSBjoern A. Zeeb if (slottime != phy->slottime) {
6746c92544dSBjoern A. Zeeb phy->slottime = slottime;
675*cbb3ec25SBjoern A. Zeeb mt792x_mac_set_timeing(phy);
6766c92544dSBjoern A. Zeeb }
6776c92544dSBjoern A. Zeeb }
6786c92544dSBjoern A. Zeeb
6796c92544dSBjoern A. Zeeb if (changed & (BSS_CHANGED_BEACON |
6806c92544dSBjoern A. Zeeb BSS_CHANGED_BEACON_ENABLED))
6816c92544dSBjoern A. Zeeb mt7921_mcu_uni_add_beacon_offload(dev, hw, vif,
6826c92544dSBjoern A. Zeeb info->enable_beacon);
6836c92544dSBjoern A. Zeeb
6846c92544dSBjoern A. Zeeb /* ensure that enable txcmd_mode after bss_info */
6856c92544dSBjoern A. Zeeb if (changed & (BSS_CHANGED_QOS | BSS_CHANGED_BEACON_ENABLED))
6866c92544dSBjoern A. Zeeb mt7921_mcu_set_tx(dev, vif);
6876c92544dSBjoern A. Zeeb
6886c92544dSBjoern A. Zeeb if (changed & BSS_CHANGED_PS)
6896c92544dSBjoern A. Zeeb mt7921_mcu_uni_bss_ps(dev, vif);
6906c92544dSBjoern A. Zeeb
6916c92544dSBjoern A. Zeeb if (changed & BSS_CHANGED_ASSOC) {
6926c92544dSBjoern A. Zeeb mt7921_mcu_sta_update(dev, NULL, vif, true,
6936c92544dSBjoern A. Zeeb MT76_STA_INFO_STATE_ASSOC);
6946c92544dSBjoern A. Zeeb mt7921_mcu_set_beacon_filter(dev, vif, vif->cfg.assoc);
6956c92544dSBjoern A. Zeeb }
6966c92544dSBjoern A. Zeeb
6976c92544dSBjoern A. Zeeb if (changed & BSS_CHANGED_ARP_FILTER) {
698*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
6996c92544dSBjoern A. Zeeb
7006c92544dSBjoern A. Zeeb mt76_connac_mcu_update_arp_filter(&dev->mt76, &mvif->mt76,
7016c92544dSBjoern A. Zeeb info);
7026c92544dSBjoern A. Zeeb }
7036c92544dSBjoern A. Zeeb
704*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
7056c92544dSBjoern A. Zeeb }
7066c92544dSBjoern A. Zeeb
mt7921_mac_sta_add(struct mt76_dev * mdev,struct ieee80211_vif * vif,struct ieee80211_sta * sta)7076c92544dSBjoern A. Zeeb int mt7921_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
7086c92544dSBjoern A. Zeeb struct ieee80211_sta *sta)
7096c92544dSBjoern A. Zeeb {
710*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
711*cbb3ec25SBjoern A. Zeeb struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
712*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
7136c92544dSBjoern A. Zeeb int ret, idx;
7146c92544dSBjoern A. Zeeb
715*cbb3ec25SBjoern A. Zeeb idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT792x_WTBL_STA - 1);
7166c92544dSBjoern A. Zeeb if (idx < 0)
7176c92544dSBjoern A. Zeeb return -ENOSPC;
7186c92544dSBjoern A. Zeeb
719*cbb3ec25SBjoern A. Zeeb INIT_LIST_HEAD(&msta->wcid.poll_list);
7206c92544dSBjoern A. Zeeb msta->vif = mvif;
7216c92544dSBjoern A. Zeeb msta->wcid.sta = 1;
7226c92544dSBjoern A. Zeeb msta->wcid.idx = idx;
7236c92544dSBjoern A. Zeeb msta->wcid.phy_idx = mvif->mt76.band_idx;
7246c92544dSBjoern A. Zeeb msta->wcid.tx_info |= MT_WCID_TX_INFO_SET;
7256c92544dSBjoern A. Zeeb msta->last_txs = jiffies;
7266c92544dSBjoern A. Zeeb
7276c92544dSBjoern A. Zeeb ret = mt76_connac_pm_wake(&dev->mphy, &dev->pm);
7286c92544dSBjoern A. Zeeb if (ret)
7296c92544dSBjoern A. Zeeb return ret;
7306c92544dSBjoern A. Zeeb
7316c92544dSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION)
7326c92544dSBjoern A. Zeeb mvif->wep_sta = msta;
7336c92544dSBjoern A. Zeeb
7346c92544dSBjoern A. Zeeb mt7921_mac_wtbl_update(dev, idx,
7356c92544dSBjoern A. Zeeb MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
7366c92544dSBjoern A. Zeeb
7376c92544dSBjoern A. Zeeb ret = mt7921_mcu_sta_update(dev, sta, vif, true,
7386c92544dSBjoern A. Zeeb MT76_STA_INFO_STATE_NONE);
7396c92544dSBjoern A. Zeeb if (ret)
7406c92544dSBjoern A. Zeeb return ret;
7416c92544dSBjoern A. Zeeb
7426c92544dSBjoern A. Zeeb mt76_connac_power_save_sched(&dev->mphy, &dev->pm);
7436c92544dSBjoern A. Zeeb
7446c92544dSBjoern A. Zeeb return 0;
7456c92544dSBjoern A. Zeeb }
7466c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt7921_mac_sta_add);
7476c92544dSBjoern A. Zeeb
mt7921_mac_sta_assoc(struct mt76_dev * mdev,struct ieee80211_vif * vif,struct ieee80211_sta * sta)7486c92544dSBjoern A. Zeeb void mt7921_mac_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif,
7496c92544dSBjoern A. Zeeb struct ieee80211_sta *sta)
7506c92544dSBjoern A. Zeeb {
751*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
752*cbb3ec25SBjoern A. Zeeb struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
753*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
7546c92544dSBjoern A. Zeeb
755*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
7566c92544dSBjoern A. Zeeb
7576c92544dSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
7586c92544dSBjoern A. Zeeb mt76_connac_mcu_uni_add_bss(&dev->mphy, vif, &mvif->sta.wcid,
759*cbb3ec25SBjoern A. Zeeb true, mvif->ctx);
760*cbb3ec25SBjoern A. Zeeb
761*cbb3ec25SBjoern A. Zeeb ewma_avg_signal_init(&msta->avg_ack_signal);
7626c92544dSBjoern A. Zeeb
7636c92544dSBjoern A. Zeeb mt7921_mac_wtbl_update(dev, msta->wcid.idx,
7646c92544dSBjoern A. Zeeb MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
7656c92544dSBjoern A. Zeeb memset(msta->airtime_ac, 0, sizeof(msta->airtime_ac));
7666c92544dSBjoern A. Zeeb
7676c92544dSBjoern A. Zeeb mt7921_mcu_sta_update(dev, sta, vif, true, MT76_STA_INFO_STATE_ASSOC);
7686c92544dSBjoern A. Zeeb
769*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
7706c92544dSBjoern A. Zeeb }
7716c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt7921_mac_sta_assoc);
7726c92544dSBjoern A. Zeeb
mt7921_mac_sta_remove(struct mt76_dev * mdev,struct ieee80211_vif * vif,struct ieee80211_sta * sta)7736c92544dSBjoern A. Zeeb void mt7921_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
7746c92544dSBjoern A. Zeeb struct ieee80211_sta *sta)
7756c92544dSBjoern A. Zeeb {
776*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
777*cbb3ec25SBjoern A. Zeeb struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
7786c92544dSBjoern A. Zeeb
7796c92544dSBjoern A. Zeeb mt76_connac_free_pending_tx_skbs(&dev->pm, &msta->wcid);
7806c92544dSBjoern A. Zeeb mt76_connac_pm_wake(&dev->mphy, &dev->pm);
7816c92544dSBjoern A. Zeeb
7826c92544dSBjoern A. Zeeb mt7921_mcu_sta_update(dev, sta, vif, false, MT76_STA_INFO_STATE_NONE);
7836c92544dSBjoern A. Zeeb mt7921_mac_wtbl_update(dev, msta->wcid.idx,
7846c92544dSBjoern A. Zeeb MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
7856c92544dSBjoern A. Zeeb
7866c92544dSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION) {
787*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
7886c92544dSBjoern A. Zeeb
7896c92544dSBjoern A. Zeeb mvif->wep_sta = NULL;
7906c92544dSBjoern A. Zeeb ewma_rssi_init(&mvif->rssi);
7916c92544dSBjoern A. Zeeb if (!sta->tdls)
7926c92544dSBjoern A. Zeeb mt76_connac_mcu_uni_add_bss(&dev->mphy, vif,
793*cbb3ec25SBjoern A. Zeeb &mvif->sta.wcid, false,
794*cbb3ec25SBjoern A. Zeeb mvif->ctx);
7956c92544dSBjoern A. Zeeb }
7966c92544dSBjoern A. Zeeb
797*cbb3ec25SBjoern A. Zeeb spin_lock_bh(&dev->mt76.sta_poll_lock);
798*cbb3ec25SBjoern A. Zeeb if (!list_empty(&msta->wcid.poll_list))
799*cbb3ec25SBjoern A. Zeeb list_del_init(&msta->wcid.poll_list);
800*cbb3ec25SBjoern A. Zeeb spin_unlock_bh(&dev->mt76.sta_poll_lock);
8016c92544dSBjoern A. Zeeb
8026c92544dSBjoern A. Zeeb mt76_connac_power_save_sched(&dev->mphy, &dev->pm);
8036c92544dSBjoern A. Zeeb }
8046c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt7921_mac_sta_remove);
8056c92544dSBjoern A. Zeeb
mt7921_set_rts_threshold(struct ieee80211_hw * hw,u32 val)8066c92544dSBjoern A. Zeeb static int mt7921_set_rts_threshold(struct ieee80211_hw *hw, u32 val)
8076c92544dSBjoern A. Zeeb {
808*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
8096c92544dSBjoern A. Zeeb
810*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
8116c92544dSBjoern A. Zeeb mt76_connac_mcu_set_rts_thresh(&dev->mt76, val, 0);
812*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
8136c92544dSBjoern A. Zeeb
8146c92544dSBjoern A. Zeeb return 0;
8156c92544dSBjoern A. Zeeb }
8166c92544dSBjoern A. Zeeb
8176c92544dSBjoern A. Zeeb static int
mt7921_ampdu_action(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_ampdu_params * params)8186c92544dSBjoern A. Zeeb mt7921_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
8196c92544dSBjoern A. Zeeb struct ieee80211_ampdu_params *params)
8206c92544dSBjoern A. Zeeb {
8216c92544dSBjoern A. Zeeb enum ieee80211_ampdu_mlme_action action = params->action;
822*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
8236c92544dSBjoern A. Zeeb struct ieee80211_sta *sta = params->sta;
8246c92544dSBjoern A. Zeeb struct ieee80211_txq *txq = sta->txq[params->tid];
825*cbb3ec25SBjoern A. Zeeb struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
8266c92544dSBjoern A. Zeeb u16 tid = params->tid;
8276c92544dSBjoern A. Zeeb u16 ssn = params->ssn;
8286c92544dSBjoern A. Zeeb struct mt76_txq *mtxq;
8296c92544dSBjoern A. Zeeb int ret = 0;
8306c92544dSBjoern A. Zeeb
8316c92544dSBjoern A. Zeeb if (!txq)
8326c92544dSBjoern A. Zeeb return -EINVAL;
8336c92544dSBjoern A. Zeeb
8346c92544dSBjoern A. Zeeb mtxq = (struct mt76_txq *)txq->drv_priv;
8356c92544dSBjoern A. Zeeb
836*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
8376c92544dSBjoern A. Zeeb switch (action) {
8386c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_RX_START:
8396c92544dSBjoern A. Zeeb mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, ssn,
8406c92544dSBjoern A. Zeeb params->buf_size);
8416c92544dSBjoern A. Zeeb mt7921_mcu_uni_rx_ba(dev, params, true);
8426c92544dSBjoern A. Zeeb break;
8436c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_RX_STOP:
8446c92544dSBjoern A. Zeeb mt76_rx_aggr_stop(&dev->mt76, &msta->wcid, tid);
8456c92544dSBjoern A. Zeeb mt7921_mcu_uni_rx_ba(dev, params, false);
8466c92544dSBjoern A. Zeeb break;
8476c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_OPERATIONAL:
8486c92544dSBjoern A. Zeeb mtxq->aggr = true;
8496c92544dSBjoern A. Zeeb mtxq->send_bar = false;
8506c92544dSBjoern A. Zeeb mt7921_mcu_uni_tx_ba(dev, params, true);
8516c92544dSBjoern A. Zeeb break;
8526c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_STOP_FLUSH:
8536c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
8546c92544dSBjoern A. Zeeb mtxq->aggr = false;
855*cbb3ec25SBjoern A. Zeeb clear_bit(tid, &msta->wcid.ampdu_state);
8566c92544dSBjoern A. Zeeb mt7921_mcu_uni_tx_ba(dev, params, false);
8576c92544dSBjoern A. Zeeb break;
8586c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_START:
859*cbb3ec25SBjoern A. Zeeb set_bit(tid, &msta->wcid.ampdu_state);
8606c92544dSBjoern A. Zeeb ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;
8616c92544dSBjoern A. Zeeb break;
8626c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_STOP_CONT:
8636c92544dSBjoern A. Zeeb mtxq->aggr = false;
864*cbb3ec25SBjoern A. Zeeb clear_bit(tid, &msta->wcid.ampdu_state);
8656c92544dSBjoern A. Zeeb mt7921_mcu_uni_tx_ba(dev, params, false);
8666c92544dSBjoern A. Zeeb ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
8676c92544dSBjoern A. Zeeb break;
8686c92544dSBjoern A. Zeeb }
869*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
8706c92544dSBjoern A. Zeeb
8716c92544dSBjoern A. Zeeb return ret;
8726c92544dSBjoern A. Zeeb }
8736c92544dSBjoern 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)8746c92544dSBjoern A. Zeeb static int mt7921_sta_state(struct ieee80211_hw *hw,
8756c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
8766c92544dSBjoern A. Zeeb struct ieee80211_sta *sta,
8776c92544dSBjoern A. Zeeb enum ieee80211_sta_state old_state,
8786c92544dSBjoern A. Zeeb enum ieee80211_sta_state new_state)
8796c92544dSBjoern A. Zeeb {
880*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
8816c92544dSBjoern A. Zeeb
8826c92544dSBjoern A. Zeeb if (dev->pm.ds_enable) {
883*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
8846c92544dSBjoern A. Zeeb mt76_connac_sta_state_dp(&dev->mt76, old_state, new_state);
885*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
8866c92544dSBjoern A. Zeeb }
8876c92544dSBjoern A. Zeeb
8886c92544dSBjoern A. Zeeb return mt76_sta_state(hw, vif, sta, old_state, new_state);
8896c92544dSBjoern A. Zeeb }
8906c92544dSBjoern A. Zeeb
mt7921_scan_work(struct work_struct * work)8916c92544dSBjoern A. Zeeb void mt7921_scan_work(struct work_struct *work)
8926c92544dSBjoern A. Zeeb {
893*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy;
8946c92544dSBjoern A. Zeeb
895*cbb3ec25SBjoern A. Zeeb phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy,
8966c92544dSBjoern A. Zeeb scan_work.work);
8976c92544dSBjoern A. Zeeb
8986c92544dSBjoern A. Zeeb while (true) {
8996c92544dSBjoern A. Zeeb struct mt76_connac2_mcu_rxd *rxd;
9006c92544dSBjoern A. Zeeb struct sk_buff *skb;
9016c92544dSBjoern A. Zeeb
9026c92544dSBjoern A. Zeeb spin_lock_bh(&phy->dev->mt76.lock);
9036c92544dSBjoern A. Zeeb skb = __skb_dequeue(&phy->scan_event_list);
9046c92544dSBjoern A. Zeeb spin_unlock_bh(&phy->dev->mt76.lock);
9056c92544dSBjoern A. Zeeb
9066c92544dSBjoern A. Zeeb if (!skb)
9076c92544dSBjoern A. Zeeb break;
9086c92544dSBjoern A. Zeeb
9096c92544dSBjoern A. Zeeb rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
9106c92544dSBjoern A. Zeeb if (rxd->eid == MCU_EVENT_SCHED_SCAN_DONE) {
9116c92544dSBjoern A. Zeeb ieee80211_sched_scan_results(phy->mt76->hw);
9126c92544dSBjoern A. Zeeb } else if (test_and_clear_bit(MT76_HW_SCANNING,
9136c92544dSBjoern A. Zeeb &phy->mt76->state)) {
9146c92544dSBjoern A. Zeeb struct cfg80211_scan_info info = {
9156c92544dSBjoern A. Zeeb .aborted = false,
9166c92544dSBjoern A. Zeeb };
9176c92544dSBjoern A. Zeeb
9186c92544dSBjoern A. Zeeb ieee80211_scan_completed(phy->mt76->hw, &info);
9196c92544dSBjoern A. Zeeb }
9206c92544dSBjoern A. Zeeb dev_kfree_skb(skb);
9216c92544dSBjoern A. Zeeb }
9226c92544dSBjoern A. Zeeb }
9236c92544dSBjoern A. Zeeb
9246c92544dSBjoern A. Zeeb static int
mt7921_hw_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_scan_request * req)9256c92544dSBjoern A. Zeeb mt7921_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
9266c92544dSBjoern A. Zeeb struct ieee80211_scan_request *req)
9276c92544dSBjoern A. Zeeb {
928*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
9296c92544dSBjoern A. Zeeb struct mt76_phy *mphy = hw->priv;
9306c92544dSBjoern A. Zeeb int err;
9316c92544dSBjoern A. Zeeb
932*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
9336c92544dSBjoern A. Zeeb err = mt76_connac_mcu_hw_scan(mphy, vif, req);
934*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
9356c92544dSBjoern A. Zeeb
9366c92544dSBjoern A. Zeeb return err;
9376c92544dSBjoern A. Zeeb }
9386c92544dSBjoern A. Zeeb
9396c92544dSBjoern A. Zeeb static void
mt7921_cancel_hw_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif)9406c92544dSBjoern A. Zeeb mt7921_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
9416c92544dSBjoern A. Zeeb {
942*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
9436c92544dSBjoern A. Zeeb struct mt76_phy *mphy = hw->priv;
9446c92544dSBjoern A. Zeeb
945*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
9466c92544dSBjoern A. Zeeb mt76_connac_mcu_cancel_hw_scan(mphy, vif);
947*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
9486c92544dSBjoern A. Zeeb }
9496c92544dSBjoern A. Zeeb
9506c92544dSBjoern 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)9516c92544dSBjoern A. Zeeb mt7921_start_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
9526c92544dSBjoern A. Zeeb struct cfg80211_sched_scan_request *req,
9536c92544dSBjoern A. Zeeb struct ieee80211_scan_ies *ies)
9546c92544dSBjoern A. Zeeb {
955*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
9566c92544dSBjoern A. Zeeb struct mt76_phy *mphy = hw->priv;
9576c92544dSBjoern A. Zeeb int err;
9586c92544dSBjoern A. Zeeb
959*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
9606c92544dSBjoern A. Zeeb
9616c92544dSBjoern A. Zeeb err = mt76_connac_mcu_sched_scan_req(mphy, vif, req);
9626c92544dSBjoern A. Zeeb if (err < 0)
9636c92544dSBjoern A. Zeeb goto out;
9646c92544dSBjoern A. Zeeb
9656c92544dSBjoern A. Zeeb err = mt76_connac_mcu_sched_scan_enable(mphy, vif, true);
9666c92544dSBjoern A. Zeeb out:
967*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
9686c92544dSBjoern A. Zeeb
9696c92544dSBjoern A. Zeeb return err;
9706c92544dSBjoern A. Zeeb }
9716c92544dSBjoern A. Zeeb
9726c92544dSBjoern A. Zeeb static int
mt7921_stop_sched_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif)9736c92544dSBjoern A. Zeeb mt7921_stop_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
9746c92544dSBjoern A. Zeeb {
975*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
9766c92544dSBjoern A. Zeeb struct mt76_phy *mphy = hw->priv;
9776c92544dSBjoern A. Zeeb int err;
9786c92544dSBjoern A. Zeeb
979*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
9806c92544dSBjoern A. Zeeb err = mt76_connac_mcu_sched_scan_enable(mphy, vif, false);
981*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
9826c92544dSBjoern A. Zeeb
9836c92544dSBjoern A. Zeeb return err;
9846c92544dSBjoern A. Zeeb }
9856c92544dSBjoern A. Zeeb
9866c92544dSBjoern A. Zeeb static int
mt7921_set_antenna(struct ieee80211_hw * hw,u32 tx_ant,u32 rx_ant)9876c92544dSBjoern A. Zeeb mt7921_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
9886c92544dSBjoern A. Zeeb {
989*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
990*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
9916c92544dSBjoern A. Zeeb int max_nss = hweight8(hw->wiphy->available_antennas_tx);
9926c92544dSBjoern A. Zeeb
9936c92544dSBjoern A. Zeeb if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss)
9946c92544dSBjoern A. Zeeb return -EINVAL;
9956c92544dSBjoern A. Zeeb
9966c92544dSBjoern A. Zeeb if ((BIT(hweight8(tx_ant)) - 1) != tx_ant)
997*cbb3ec25SBjoern A. Zeeb return -EINVAL;
9986c92544dSBjoern A. Zeeb
999*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
10006c92544dSBjoern A. Zeeb
10016c92544dSBjoern A. Zeeb phy->mt76->antenna_mask = tx_ant;
10026c92544dSBjoern A. Zeeb phy->mt76->chainmask = tx_ant;
10036c92544dSBjoern A. Zeeb
10046c92544dSBjoern A. Zeeb mt76_set_stream_caps(phy->mt76, true);
10056c92544dSBjoern A. Zeeb mt7921_set_stream_he_caps(phy);
10066c92544dSBjoern A. Zeeb
1007*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
10086c92544dSBjoern A. Zeeb
10096c92544dSBjoern A. Zeeb return 0;
10106c92544dSBjoern A. Zeeb }
10116c92544dSBjoern A. Zeeb
10126c92544dSBjoern A. Zeeb #ifdef CONFIG_PM
mt7921_suspend(struct ieee80211_hw * hw,struct cfg80211_wowlan * wowlan)10136c92544dSBjoern A. Zeeb static int mt7921_suspend(struct ieee80211_hw *hw,
10146c92544dSBjoern A. Zeeb struct cfg80211_wowlan *wowlan)
10156c92544dSBjoern A. Zeeb {
1016*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
1017*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
10186c92544dSBjoern A. Zeeb
10196c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&phy->scan_work);
10206c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&phy->mt76->mac_work);
10216c92544dSBjoern A. Zeeb
10226c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&dev->pm.ps_work);
10236c92544dSBjoern A. Zeeb mt76_connac_free_pending_tx_skbs(&dev->pm, NULL);
10246c92544dSBjoern A. Zeeb
1025*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
10266c92544dSBjoern A. Zeeb
10276c92544dSBjoern A. Zeeb clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
10286c92544dSBjoern A. Zeeb ieee80211_iterate_active_interfaces(hw,
10296c92544dSBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL,
10306c92544dSBjoern A. Zeeb mt7921_mcu_set_suspend_iter,
10316c92544dSBjoern A. Zeeb &dev->mphy);
10326c92544dSBjoern A. Zeeb
1033*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
10346c92544dSBjoern A. Zeeb
10356c92544dSBjoern A. Zeeb return 0;
10366c92544dSBjoern A. Zeeb }
10376c92544dSBjoern A. Zeeb
mt7921_resume(struct ieee80211_hw * hw)10386c92544dSBjoern A. Zeeb static int mt7921_resume(struct ieee80211_hw *hw)
10396c92544dSBjoern A. Zeeb {
1040*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
1041*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
10426c92544dSBjoern A. Zeeb
1043*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
10446c92544dSBjoern A. Zeeb
10456c92544dSBjoern A. Zeeb set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
10466c92544dSBjoern A. Zeeb ieee80211_iterate_active_interfaces(hw,
10476c92544dSBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL,
10486c92544dSBjoern A. Zeeb mt76_connac_mcu_set_suspend_iter,
10496c92544dSBjoern A. Zeeb &dev->mphy);
10506c92544dSBjoern A. Zeeb
10516c92544dSBjoern A. Zeeb ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
1052*cbb3ec25SBjoern A. Zeeb MT792x_WATCHDOG_TIME);
10536c92544dSBjoern A. Zeeb
1054*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
10556c92544dSBjoern A. Zeeb
10566c92544dSBjoern A. Zeeb return 0;
10576c92544dSBjoern A. Zeeb }
10586c92544dSBjoern A. Zeeb
mt7921_set_rekey_data(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct cfg80211_gtk_rekey_data * data)10596c92544dSBjoern A. Zeeb static void mt7921_set_rekey_data(struct ieee80211_hw *hw,
10606c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
10616c92544dSBjoern A. Zeeb struct cfg80211_gtk_rekey_data *data)
10626c92544dSBjoern A. Zeeb {
1063*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
10646c92544dSBjoern A. Zeeb
1065*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
10666c92544dSBjoern A. Zeeb mt76_connac_mcu_update_gtk_rekey(hw, vif, data);
1067*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
10686c92544dSBjoern A. Zeeb }
10696c92544dSBjoern A. Zeeb #endif /* CONFIG_PM */
10706c92544dSBjoern A. Zeeb
mt7921_sta_set_decap_offload(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta,bool enabled)10716c92544dSBjoern A. Zeeb static void mt7921_sta_set_decap_offload(struct ieee80211_hw *hw,
10726c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
10736c92544dSBjoern A. Zeeb struct ieee80211_sta *sta,
10746c92544dSBjoern A. Zeeb bool enabled)
10756c92544dSBjoern A. Zeeb {
1076*cbb3ec25SBjoern A. Zeeb struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
1077*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
10786c92544dSBjoern A. Zeeb
1079*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
10806c92544dSBjoern A. Zeeb
10816c92544dSBjoern A. Zeeb if (enabled)
10826c92544dSBjoern A. Zeeb set_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags);
10836c92544dSBjoern A. Zeeb else
10846c92544dSBjoern A. Zeeb clear_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags);
10856c92544dSBjoern A. Zeeb
10866c92544dSBjoern A. Zeeb mt76_connac_mcu_sta_update_hdr_trans(&dev->mt76, vif, &msta->wcid,
10876c92544dSBjoern A. Zeeb MCU_UNI_CMD(STA_REC_UPDATE));
10886c92544dSBjoern A. Zeeb
1089*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
10906c92544dSBjoern A. Zeeb }
10916c92544dSBjoern A. Zeeb
10926c92544dSBjoern A. Zeeb #if IS_ENABLED(CONFIG_IPV6)
mt7921_ipv6_addr_change(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct inet6_dev * idev)10936c92544dSBjoern A. Zeeb static void mt7921_ipv6_addr_change(struct ieee80211_hw *hw,
10946c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
10956c92544dSBjoern A. Zeeb struct inet6_dev *idev)
10966c92544dSBjoern A. Zeeb {
1097*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1098*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mvif->phy->dev;
10996c92544dSBjoern A. Zeeb struct inet6_ifaddr *ifa;
11006c92544dSBjoern A. Zeeb struct in6_addr ns_addrs[IEEE80211_BSS_ARP_ADDR_LIST_LEN];
11016c92544dSBjoern A. Zeeb struct sk_buff *skb;
11026c92544dSBjoern A. Zeeb u8 i, idx = 0;
11036c92544dSBjoern A. Zeeb
11046c92544dSBjoern A. Zeeb struct {
11056c92544dSBjoern A. Zeeb struct {
11066c92544dSBjoern A. Zeeb u8 bss_idx;
11076c92544dSBjoern A. Zeeb u8 pad[3];
11086c92544dSBjoern A. Zeeb } __packed hdr;
11096c92544dSBjoern A. Zeeb struct mt76_connac_arpns_tlv arpns;
11106c92544dSBjoern A. Zeeb } req_hdr = {
11116c92544dSBjoern A. Zeeb .hdr = {
11126c92544dSBjoern A. Zeeb .bss_idx = mvif->mt76.idx,
11136c92544dSBjoern A. Zeeb },
11146c92544dSBjoern A. Zeeb .arpns = {
11156c92544dSBjoern A. Zeeb .tag = cpu_to_le16(UNI_OFFLOAD_OFFLOAD_ND),
11166c92544dSBjoern A. Zeeb .mode = 2, /* update */
11176c92544dSBjoern A. Zeeb .option = 1, /* update only */
11186c92544dSBjoern A. Zeeb },
11196c92544dSBjoern A. Zeeb };
11206c92544dSBjoern A. Zeeb
11216c92544dSBjoern A. Zeeb read_lock_bh(&idev->lock);
11226c92544dSBjoern A. Zeeb list_for_each_entry(ifa, &idev->addr_list, if_list) {
11236c92544dSBjoern A. Zeeb if (ifa->flags & IFA_F_TENTATIVE)
11246c92544dSBjoern A. Zeeb continue;
11256c92544dSBjoern A. Zeeb ns_addrs[idx] = ifa->addr;
11266c92544dSBjoern A. Zeeb if (++idx >= IEEE80211_BSS_ARP_ADDR_LIST_LEN)
11276c92544dSBjoern A. Zeeb break;
11286c92544dSBjoern A. Zeeb }
11296c92544dSBjoern A. Zeeb read_unlock_bh(&idev->lock);
11306c92544dSBjoern A. Zeeb
11316c92544dSBjoern A. Zeeb if (!idx)
11326c92544dSBjoern A. Zeeb return;
11336c92544dSBjoern A. Zeeb
11346c92544dSBjoern A. Zeeb req_hdr.arpns.ips_num = idx;
11356c92544dSBjoern A. Zeeb req_hdr.arpns.len = cpu_to_le16(sizeof(struct mt76_connac_arpns_tlv)
11366c92544dSBjoern A. Zeeb + idx * sizeof(struct in6_addr));
11376c92544dSBjoern A. Zeeb skb = __mt76_mcu_msg_alloc(&dev->mt76, &req_hdr,
11386c92544dSBjoern A. Zeeb sizeof(req_hdr) + idx * sizeof(struct in6_addr),
11396c92544dSBjoern A. Zeeb sizeof(req_hdr), GFP_ATOMIC);
11406c92544dSBjoern A. Zeeb if (!skb)
11416c92544dSBjoern A. Zeeb return;
11426c92544dSBjoern A. Zeeb
11436c92544dSBjoern A. Zeeb for (i = 0; i < idx; i++)
11446c92544dSBjoern A. Zeeb skb_put_data(skb, &ns_addrs[i].in6_u, sizeof(struct in6_addr));
11456c92544dSBjoern A. Zeeb
11466c92544dSBjoern A. Zeeb skb_queue_tail(&dev->ipv6_ns_list, skb);
11476c92544dSBjoern A. Zeeb
11486c92544dSBjoern A. Zeeb ieee80211_queue_work(dev->mt76.hw, &dev->ipv6_ns_work);
11496c92544dSBjoern A. Zeeb }
11506c92544dSBjoern A. Zeeb #endif
11516c92544dSBjoern A. Zeeb
mt7921_set_tx_sar_pwr(struct ieee80211_hw * hw,const struct cfg80211_sar_specs * sar)11526c92544dSBjoern A. Zeeb int mt7921_set_tx_sar_pwr(struct ieee80211_hw *hw,
11536c92544dSBjoern A. Zeeb const struct cfg80211_sar_specs *sar)
11546c92544dSBjoern A. Zeeb {
11556c92544dSBjoern A. Zeeb struct mt76_phy *mphy = hw->priv;
11566c92544dSBjoern A. Zeeb
11576c92544dSBjoern A. Zeeb if (sar) {
1158*cbb3ec25SBjoern A. Zeeb int err = mt76_init_sar_power(hw, sar);
1159*cbb3ec25SBjoern A. Zeeb
11606c92544dSBjoern A. Zeeb if (err)
11616c92544dSBjoern A. Zeeb return err;
11626c92544dSBjoern A. Zeeb }
1163*cbb3ec25SBjoern A. Zeeb mt792x_init_acpi_sar_power(mt792x_hw_phy(hw), !sar);
11646c92544dSBjoern A. Zeeb
1165*cbb3ec25SBjoern A. Zeeb return mt76_connac_mcu_set_rate_txpower(mphy);
11666c92544dSBjoern A. Zeeb }
11676c92544dSBjoern A. Zeeb
mt7921_set_sar_specs(struct ieee80211_hw * hw,const struct cfg80211_sar_specs * sar)11686c92544dSBjoern A. Zeeb static int mt7921_set_sar_specs(struct ieee80211_hw *hw,
11696c92544dSBjoern A. Zeeb const struct cfg80211_sar_specs *sar)
11706c92544dSBjoern A. Zeeb {
1171*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
11726c92544dSBjoern A. Zeeb int err;
11736c92544dSBjoern A. Zeeb
1174*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
1175*cbb3ec25SBjoern A. Zeeb err = mt7921_mcu_set_clc(dev, dev->mt76.alpha2,
1176*cbb3ec25SBjoern A. Zeeb dev->country_ie_env);
1177*cbb3ec25SBjoern A. Zeeb if (err < 0)
1178*cbb3ec25SBjoern A. Zeeb goto out;
1179*cbb3ec25SBjoern A. Zeeb
11806c92544dSBjoern A. Zeeb err = mt7921_set_tx_sar_pwr(hw, sar);
1181*cbb3ec25SBjoern A. Zeeb out:
1182*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
11836c92544dSBjoern A. Zeeb
11846c92544dSBjoern A. Zeeb return err;
11856c92544dSBjoern A. Zeeb }
11866c92544dSBjoern A. Zeeb
11876c92544dSBjoern A. Zeeb static void
mt7921_channel_switch_beacon(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct cfg80211_chan_def * chandef)11886c92544dSBjoern A. Zeeb mt7921_channel_switch_beacon(struct ieee80211_hw *hw,
11896c92544dSBjoern A. Zeeb struct ieee80211_vif *vif,
11906c92544dSBjoern A. Zeeb struct cfg80211_chan_def *chandef)
11916c92544dSBjoern A. Zeeb {
1192*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
11936c92544dSBjoern A. Zeeb
1194*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
11956c92544dSBjoern A. Zeeb mt7921_mcu_uni_add_beacon_offload(dev, hw, vif, true);
1196*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
11976c92544dSBjoern A. Zeeb }
11986c92544dSBjoern A. Zeeb
11996c92544dSBjoern A. Zeeb static int
mt7921_start_ap(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)12006c92544dSBjoern A. Zeeb mt7921_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
12016c92544dSBjoern A. Zeeb struct ieee80211_bss_conf *link_conf)
12026c92544dSBjoern A. Zeeb {
1203*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1204*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
1205*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
12066c92544dSBjoern A. Zeeb int err;
12076c92544dSBjoern A. Zeeb
1208*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
12096c92544dSBjoern A. Zeeb
12106c92544dSBjoern A. Zeeb err = mt76_connac_mcu_uni_add_bss(phy->mt76, vif, &mvif->sta.wcid,
1211*cbb3ec25SBjoern A. Zeeb true, mvif->ctx);
12126c92544dSBjoern A. Zeeb if (err)
12136c92544dSBjoern A. Zeeb goto out;
12146c92544dSBjoern A. Zeeb
12156c92544dSBjoern A. Zeeb err = mt7921_mcu_set_bss_pm(dev, vif, true);
12166c92544dSBjoern A. Zeeb if (err)
12176c92544dSBjoern A. Zeeb goto out;
12186c92544dSBjoern A. Zeeb
12196c92544dSBjoern A. Zeeb err = mt7921_mcu_sta_update(dev, NULL, vif, true,
12206c92544dSBjoern A. Zeeb MT76_STA_INFO_STATE_NONE);
12216c92544dSBjoern A. Zeeb out:
1222*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
12236c92544dSBjoern A. Zeeb
12246c92544dSBjoern A. Zeeb return err;
12256c92544dSBjoern A. Zeeb }
12266c92544dSBjoern A. Zeeb
12276c92544dSBjoern A. Zeeb static void
mt7921_stop_ap(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)12286c92544dSBjoern A. Zeeb mt7921_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
12296c92544dSBjoern A. Zeeb struct ieee80211_bss_conf *link_conf)
12306c92544dSBjoern A. Zeeb {
1231*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1232*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
1233*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
12346c92544dSBjoern A. Zeeb int err;
12356c92544dSBjoern A. Zeeb
1236*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
12376c92544dSBjoern A. Zeeb
12386c92544dSBjoern A. Zeeb err = mt7921_mcu_set_bss_pm(dev, vif, false);
12396c92544dSBjoern A. Zeeb if (err)
12406c92544dSBjoern A. Zeeb goto out;
12416c92544dSBjoern A. Zeeb
1242*cbb3ec25SBjoern A. Zeeb mt76_connac_mcu_uni_add_bss(phy->mt76, vif, &mvif->sta.wcid, false,
1243*cbb3ec25SBjoern A. Zeeb mvif->ctx);
12446c92544dSBjoern A. Zeeb
12456c92544dSBjoern A. Zeeb out:
1246*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
1247*cbb3ec25SBjoern A. Zeeb }
1248*cbb3ec25SBjoern A. Zeeb
1249*cbb3ec25SBjoern A. Zeeb static int
mt7921_add_chanctx(struct ieee80211_hw * hw,struct ieee80211_chanctx_conf * ctx)1250*cbb3ec25SBjoern A. Zeeb mt7921_add_chanctx(struct ieee80211_hw *hw,
1251*cbb3ec25SBjoern A. Zeeb struct ieee80211_chanctx_conf *ctx)
1252*cbb3ec25SBjoern A. Zeeb {
1253*cbb3ec25SBjoern A. Zeeb return 0;
1254*cbb3ec25SBjoern A. Zeeb }
1255*cbb3ec25SBjoern A. Zeeb
1256*cbb3ec25SBjoern A. Zeeb static void
mt7921_remove_chanctx(struct ieee80211_hw * hw,struct ieee80211_chanctx_conf * ctx)1257*cbb3ec25SBjoern A. Zeeb mt7921_remove_chanctx(struct ieee80211_hw *hw,
1258*cbb3ec25SBjoern A. Zeeb struct ieee80211_chanctx_conf *ctx)
1259*cbb3ec25SBjoern A. Zeeb {
1260*cbb3ec25SBjoern A. Zeeb }
1261*cbb3ec25SBjoern A. Zeeb
mt7921_ctx_iter(void * priv,u8 * mac,struct ieee80211_vif * vif)1262*cbb3ec25SBjoern A. Zeeb static void mt7921_ctx_iter(void *priv, u8 *mac,
1263*cbb3ec25SBjoern A. Zeeb struct ieee80211_vif *vif)
1264*cbb3ec25SBjoern A. Zeeb {
1265*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1266*cbb3ec25SBjoern A. Zeeb struct ieee80211_chanctx_conf *ctx = priv;
1267*cbb3ec25SBjoern A. Zeeb
1268*cbb3ec25SBjoern A. Zeeb if (ctx != mvif->ctx)
1269*cbb3ec25SBjoern A. Zeeb return;
1270*cbb3ec25SBjoern A. Zeeb
1271*cbb3ec25SBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_MONITOR)
1272*cbb3ec25SBjoern A. Zeeb mt7921_mcu_config_sniffer(mvif, ctx);
1273*cbb3ec25SBjoern A. Zeeb else
1274*cbb3ec25SBjoern A. Zeeb mt76_connac_mcu_uni_set_chctx(mvif->phy->mt76, &mvif->mt76, ctx);
1275*cbb3ec25SBjoern A. Zeeb }
1276*cbb3ec25SBjoern A. Zeeb
1277*cbb3ec25SBjoern A. Zeeb static void
mt7921_change_chanctx(struct ieee80211_hw * hw,struct ieee80211_chanctx_conf * ctx,u32 changed)1278*cbb3ec25SBjoern A. Zeeb mt7921_change_chanctx(struct ieee80211_hw *hw,
1279*cbb3ec25SBjoern A. Zeeb struct ieee80211_chanctx_conf *ctx,
1280*cbb3ec25SBjoern A. Zeeb u32 changed)
1281*cbb3ec25SBjoern A. Zeeb {
1282*cbb3ec25SBjoern A. Zeeb struct mt792x_phy *phy = mt792x_hw_phy(hw);
1283*cbb3ec25SBjoern A. Zeeb
1284*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(phy->dev);
1285*cbb3ec25SBjoern A. Zeeb ieee80211_iterate_active_interfaces(phy->mt76->hw,
1286*cbb3ec25SBjoern A. Zeeb IEEE80211_IFACE_ITER_ACTIVE,
1287*cbb3ec25SBjoern A. Zeeb mt7921_ctx_iter, ctx);
1288*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(phy->dev);
1289*cbb3ec25SBjoern A. Zeeb }
1290*cbb3ec25SBjoern A. Zeeb
mt7921_mgd_prepare_tx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_prep_tx_info * info)1291*cbb3ec25SBjoern A. Zeeb static void mt7921_mgd_prepare_tx(struct ieee80211_hw *hw,
1292*cbb3ec25SBjoern A. Zeeb struct ieee80211_vif *vif,
1293*cbb3ec25SBjoern A. Zeeb struct ieee80211_prep_tx_info *info)
1294*cbb3ec25SBjoern A. Zeeb {
1295*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1296*cbb3ec25SBjoern A. Zeeb struct mt792x_dev *dev = mt792x_hw_dev(hw);
1297*cbb3ec25SBjoern A. Zeeb u16 duration = info->duration ? info->duration :
1298*cbb3ec25SBjoern A. Zeeb jiffies_to_msecs(HZ);
1299*cbb3ec25SBjoern A. Zeeb
1300*cbb3ec25SBjoern A. Zeeb mt792x_mutex_acquire(dev);
1301*cbb3ec25SBjoern A. Zeeb mt7921_set_roc(mvif->phy, mvif, mvif->ctx->def.chan, duration,
1302*cbb3ec25SBjoern A. Zeeb MT7921_ROC_REQ_JOIN);
1303*cbb3ec25SBjoern A. Zeeb mt792x_mutex_release(dev);
1304*cbb3ec25SBjoern A. Zeeb }
1305*cbb3ec25SBjoern A. Zeeb
mt7921_mgd_complete_tx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_prep_tx_info * info)1306*cbb3ec25SBjoern A. Zeeb static void mt7921_mgd_complete_tx(struct ieee80211_hw *hw,
1307*cbb3ec25SBjoern A. Zeeb struct ieee80211_vif *vif,
1308*cbb3ec25SBjoern A. Zeeb struct ieee80211_prep_tx_info *info)
1309*cbb3ec25SBjoern A. Zeeb {
1310*cbb3ec25SBjoern A. Zeeb struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1311*cbb3ec25SBjoern A. Zeeb
1312*cbb3ec25SBjoern A. Zeeb mt7921_abort_roc(mvif->phy, mvif);
13136c92544dSBjoern A. Zeeb }
13146c92544dSBjoern A. Zeeb
13156c92544dSBjoern A. Zeeb const struct ieee80211_ops mt7921_ops = {
1316*cbb3ec25SBjoern A. Zeeb .tx = mt792x_tx,
13176c92544dSBjoern A. Zeeb .start = mt7921_start,
13186c92544dSBjoern A. Zeeb .stop = mt7921_stop,
13196c92544dSBjoern A. Zeeb .add_interface = mt7921_add_interface,
1320*cbb3ec25SBjoern A. Zeeb .remove_interface = mt792x_remove_interface,
13216c92544dSBjoern A. Zeeb .config = mt7921_config,
1322*cbb3ec25SBjoern A. Zeeb .conf_tx = mt792x_conf_tx,
13236c92544dSBjoern A. Zeeb .configure_filter = mt7921_configure_filter,
13246c92544dSBjoern A. Zeeb .bss_info_changed = mt7921_bss_info_changed,
13256c92544dSBjoern A. Zeeb .start_ap = mt7921_start_ap,
13266c92544dSBjoern A. Zeeb .stop_ap = mt7921_stop_ap,
13276c92544dSBjoern A. Zeeb .sta_state = mt7921_sta_state,
13286c92544dSBjoern A. Zeeb .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
13296c92544dSBjoern A. Zeeb .set_key = mt7921_set_key,
13306c92544dSBjoern A. Zeeb .sta_set_decap_offload = mt7921_sta_set_decap_offload,
13316c92544dSBjoern A. Zeeb #if IS_ENABLED(CONFIG_IPV6)
13326c92544dSBjoern A. Zeeb .ipv6_addr_change = mt7921_ipv6_addr_change,
13336c92544dSBjoern A. Zeeb #endif /* CONFIG_IPV6 */
13346c92544dSBjoern A. Zeeb .ampdu_action = mt7921_ampdu_action,
13356c92544dSBjoern A. Zeeb .set_rts_threshold = mt7921_set_rts_threshold,
13366c92544dSBjoern A. Zeeb .wake_tx_queue = mt76_wake_tx_queue,
13376c92544dSBjoern A. Zeeb .release_buffered_frames = mt76_release_buffered_frames,
13386c92544dSBjoern A. Zeeb .channel_switch_beacon = mt7921_channel_switch_beacon,
13396c92544dSBjoern A. Zeeb .get_txpower = mt76_get_txpower,
1340*cbb3ec25SBjoern A. Zeeb .get_stats = mt792x_get_stats,
1341*cbb3ec25SBjoern A. Zeeb .get_et_sset_count = mt792x_get_et_sset_count,
1342*cbb3ec25SBjoern A. Zeeb .get_et_strings = mt792x_get_et_strings,
1343*cbb3ec25SBjoern A. Zeeb .get_et_stats = mt792x_get_et_stats,
1344*cbb3ec25SBjoern A. Zeeb .get_tsf = mt792x_get_tsf,
1345*cbb3ec25SBjoern A. Zeeb .set_tsf = mt792x_set_tsf,
13466c92544dSBjoern A. Zeeb .get_survey = mt76_get_survey,
13476c92544dSBjoern A. Zeeb .get_antenna = mt76_get_antenna,
13486c92544dSBjoern A. Zeeb .set_antenna = mt7921_set_antenna,
1349*cbb3ec25SBjoern A. Zeeb .set_coverage_class = mt792x_set_coverage_class,
13506c92544dSBjoern A. Zeeb .hw_scan = mt7921_hw_scan,
13516c92544dSBjoern A. Zeeb .cancel_hw_scan = mt7921_cancel_hw_scan,
1352*cbb3ec25SBjoern A. Zeeb .sta_statistics = mt792x_sta_statistics,
13536c92544dSBjoern A. Zeeb .sched_scan_start = mt7921_start_sched_scan,
13546c92544dSBjoern A. Zeeb .sched_scan_stop = mt7921_stop_sched_scan,
13556c92544dSBjoern A. Zeeb CFG80211_TESTMODE_CMD(mt7921_testmode_cmd)
13566c92544dSBjoern A. Zeeb CFG80211_TESTMODE_DUMP(mt7921_testmode_dump)
13576c92544dSBjoern A. Zeeb #ifdef CONFIG_PM
13586c92544dSBjoern A. Zeeb .suspend = mt7921_suspend,
13596c92544dSBjoern A. Zeeb .resume = mt7921_resume,
1360*cbb3ec25SBjoern A. Zeeb .set_wakeup = mt792x_set_wakeup,
13616c92544dSBjoern A. Zeeb .set_rekey_data = mt7921_set_rekey_data,
13626c92544dSBjoern A. Zeeb #endif /* CONFIG_PM */
1363*cbb3ec25SBjoern A. Zeeb .flush = mt792x_flush,
13646c92544dSBjoern A. Zeeb .set_sar_specs = mt7921_set_sar_specs,
1365*cbb3ec25SBjoern A. Zeeb .remain_on_channel = mt7921_remain_on_channel,
1366*cbb3ec25SBjoern A. Zeeb .cancel_remain_on_channel = mt7921_cancel_remain_on_channel,
1367*cbb3ec25SBjoern A. Zeeb .add_chanctx = mt7921_add_chanctx,
1368*cbb3ec25SBjoern A. Zeeb .remove_chanctx = mt7921_remove_chanctx,
1369*cbb3ec25SBjoern A. Zeeb .change_chanctx = mt7921_change_chanctx,
1370*cbb3ec25SBjoern A. Zeeb .assign_vif_chanctx = mt792x_assign_vif_chanctx,
1371*cbb3ec25SBjoern A. Zeeb .unassign_vif_chanctx = mt792x_unassign_vif_chanctx,
1372*cbb3ec25SBjoern A. Zeeb .mgd_prepare_tx = mt7921_mgd_prepare_tx,
1373*cbb3ec25SBjoern A. Zeeb .mgd_complete_tx = mt7921_mgd_complete_tx,
13746c92544dSBjoern A. Zeeb };
13756c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt7921_ops);
13766c92544dSBjoern A. Zeeb
13776c92544dSBjoern A. Zeeb MODULE_LICENSE("Dual BSD/GPL");
13786c92544dSBjoern A. Zeeb MODULE_AUTHOR("Sean Wang <sean.wang@mediatek.com>");
1379