16c92544dSBjoern A. Zeeb // SPDX-License-Identifier: ISC
26c92544dSBjoern A. Zeeb
36c92544dSBjoern A. Zeeb #include <linux/etherdevice.h>
46c92544dSBjoern A. Zeeb #include <linux/platform_device.h>
56c92544dSBjoern A. Zeeb #include <linux/pci.h>
66c92544dSBjoern A. Zeeb #include <linux/module.h>
76c92544dSBjoern A. Zeeb #include "mt7603.h"
86c92544dSBjoern A. Zeeb #include "mac.h"
96c92544dSBjoern A. Zeeb #include "eeprom.h"
106c92544dSBjoern A. Zeeb
116c92544dSBjoern A. Zeeb static int
mt7603_start(struct ieee80211_hw * hw)126c92544dSBjoern A. Zeeb mt7603_start(struct ieee80211_hw *hw)
136c92544dSBjoern A. Zeeb {
146c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
156c92544dSBjoern A. Zeeb
166c92544dSBjoern A. Zeeb mt7603_mac_reset_counters(dev);
176c92544dSBjoern A. Zeeb mt7603_mac_start(dev);
186c92544dSBjoern A. Zeeb dev->mphy.survey_time = ktime_get_boottime();
196c92544dSBjoern A. Zeeb set_bit(MT76_STATE_RUNNING, &dev->mphy.state);
206c92544dSBjoern A. Zeeb mt7603_mac_work(&dev->mphy.mac_work.work);
216c92544dSBjoern A. Zeeb
226c92544dSBjoern A. Zeeb return 0;
236c92544dSBjoern A. Zeeb }
246c92544dSBjoern A. Zeeb
256c92544dSBjoern A. Zeeb static void
mt7603_stop(struct ieee80211_hw * hw)266c92544dSBjoern A. Zeeb mt7603_stop(struct ieee80211_hw *hw)
276c92544dSBjoern A. Zeeb {
286c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
296c92544dSBjoern A. Zeeb
306c92544dSBjoern A. Zeeb clear_bit(MT76_STATE_RUNNING, &dev->mphy.state);
316c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&dev->mphy.mac_work);
326c92544dSBjoern A. Zeeb mt7603_mac_stop(dev);
336c92544dSBjoern A. Zeeb }
346c92544dSBjoern A. Zeeb
356c92544dSBjoern A. Zeeb static int
mt7603_add_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)366c92544dSBjoern A. Zeeb mt7603_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
376c92544dSBjoern A. Zeeb {
386c92544dSBjoern A. Zeeb struct mt7603_vif *mvif = (struct mt7603_vif *)vif->drv_priv;
396c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
406c92544dSBjoern A. Zeeb struct mt76_txq *mtxq;
416c92544dSBjoern A. Zeeb u8 bc_addr[ETH_ALEN];
426c92544dSBjoern A. Zeeb int idx;
436c92544dSBjoern A. Zeeb int ret = 0;
446c92544dSBjoern A. Zeeb
456c92544dSBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
466c92544dSBjoern A. Zeeb
476c92544dSBjoern A. Zeeb mvif->idx = __ffs64(~dev->mt76.vif_mask);
486c92544dSBjoern A. Zeeb if (mvif->idx >= MT7603_MAX_INTERFACES) {
496c92544dSBjoern A. Zeeb ret = -ENOSPC;
506c92544dSBjoern A. Zeeb goto out;
516c92544dSBjoern A. Zeeb }
526c92544dSBjoern A. Zeeb
536c92544dSBjoern A. Zeeb mt76_wr(dev, MT_MAC_ADDR0(mvif->idx),
546c92544dSBjoern A. Zeeb get_unaligned_le32(vif->addr));
556c92544dSBjoern A. Zeeb mt76_wr(dev, MT_MAC_ADDR1(mvif->idx),
566c92544dSBjoern A. Zeeb (get_unaligned_le16(vif->addr + 4) |
576c92544dSBjoern A. Zeeb MT_MAC_ADDR1_VALID));
586c92544dSBjoern A. Zeeb
596c92544dSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_AP) {
606c92544dSBjoern A. Zeeb mt76_wr(dev, MT_BSSID0(mvif->idx),
616c92544dSBjoern A. Zeeb get_unaligned_le32(vif->addr));
626c92544dSBjoern A. Zeeb mt76_wr(dev, MT_BSSID1(mvif->idx),
636c92544dSBjoern A. Zeeb (get_unaligned_le16(vif->addr + 4) |
646c92544dSBjoern A. Zeeb MT_BSSID1_VALID));
656c92544dSBjoern A. Zeeb }
666c92544dSBjoern A. Zeeb
676c92544dSBjoern A. Zeeb idx = MT7603_WTBL_RESERVED - 1 - mvif->idx;
686c92544dSBjoern A. Zeeb dev->mt76.vif_mask |= BIT_ULL(mvif->idx);
69*cbb3ec25SBjoern A. Zeeb INIT_LIST_HEAD(&mvif->sta.wcid.poll_list);
706c92544dSBjoern A. Zeeb mvif->sta.wcid.idx = idx;
716c92544dSBjoern A. Zeeb mvif->sta.wcid.hw_key_idx = -1;
72*cbb3ec25SBjoern A. Zeeb mvif->sta.vif = mvif;
736c92544dSBjoern A. Zeeb mt76_packet_id_init(&mvif->sta.wcid);
746c92544dSBjoern A. Zeeb
756c92544dSBjoern A. Zeeb eth_broadcast_addr(bc_addr);
766c92544dSBjoern A. Zeeb mt7603_wtbl_init(dev, idx, mvif->idx, bc_addr);
776c92544dSBjoern A. Zeeb
786c92544dSBjoern A. Zeeb mtxq = (struct mt76_txq *)vif->txq->drv_priv;
796c92544dSBjoern A. Zeeb mtxq->wcid = idx;
806c92544dSBjoern A. Zeeb rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid);
816c92544dSBjoern A. Zeeb
826c92544dSBjoern A. Zeeb out:
836c92544dSBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
846c92544dSBjoern A. Zeeb
856c92544dSBjoern A. Zeeb return ret;
866c92544dSBjoern A. Zeeb }
876c92544dSBjoern A. Zeeb
886c92544dSBjoern A. Zeeb static void
mt7603_remove_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)896c92544dSBjoern A. Zeeb mt7603_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
906c92544dSBjoern A. Zeeb {
916c92544dSBjoern A. Zeeb struct mt7603_vif *mvif = (struct mt7603_vif *)vif->drv_priv;
926c92544dSBjoern A. Zeeb struct mt7603_sta *msta = &mvif->sta;
936c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
946c92544dSBjoern A. Zeeb int idx = msta->wcid.idx;
956c92544dSBjoern A. Zeeb
966c92544dSBjoern A. Zeeb mt76_wr(dev, MT_MAC_ADDR0(mvif->idx), 0);
976c92544dSBjoern A. Zeeb mt76_wr(dev, MT_MAC_ADDR1(mvif->idx), 0);
986c92544dSBjoern A. Zeeb mt76_wr(dev, MT_BSSID0(mvif->idx), 0);
996c92544dSBjoern A. Zeeb mt76_wr(dev, MT_BSSID1(mvif->idx), 0);
1006c92544dSBjoern A. Zeeb mt7603_beacon_set_timer(dev, mvif->idx, 0);
1016c92544dSBjoern A. Zeeb
1026c92544dSBjoern A. Zeeb rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
1036c92544dSBjoern A. Zeeb
104*cbb3ec25SBjoern A. Zeeb spin_lock_bh(&dev->mt76.sta_poll_lock);
105*cbb3ec25SBjoern A. Zeeb if (!list_empty(&msta->wcid.poll_list))
106*cbb3ec25SBjoern A. Zeeb list_del_init(&msta->wcid.poll_list);
107*cbb3ec25SBjoern A. Zeeb spin_unlock_bh(&dev->mt76.sta_poll_lock);
1086c92544dSBjoern A. Zeeb
1096c92544dSBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
1106c92544dSBjoern A. Zeeb dev->mt76.vif_mask &= ~BIT_ULL(mvif->idx);
1116c92544dSBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
1126c92544dSBjoern A. Zeeb
1136c92544dSBjoern A. Zeeb mt76_packet_id_flush(&dev->mt76, &mvif->sta.wcid);
1146c92544dSBjoern A. Zeeb }
1156c92544dSBjoern A. Zeeb
mt7603_init_edcca(struct mt7603_dev * dev)1166c92544dSBjoern A. Zeeb void mt7603_init_edcca(struct mt7603_dev *dev)
1176c92544dSBjoern A. Zeeb {
1186c92544dSBjoern A. Zeeb /* Set lower signal level to -65dBm */
1196c92544dSBjoern A. Zeeb mt76_rmw_field(dev, MT_RXTD(8), MT_RXTD_8_LOWER_SIGNAL, 0x23);
1206c92544dSBjoern A. Zeeb
1216c92544dSBjoern A. Zeeb /* clear previous energy detect monitor results */
1226c92544dSBjoern A. Zeeb mt76_rr(dev, MT_MIB_STAT_ED);
1236c92544dSBjoern A. Zeeb
1246c92544dSBjoern A. Zeeb if (dev->ed_monitor)
1256c92544dSBjoern A. Zeeb mt76_set(dev, MT_MIB_CTL, MT_MIB_CTL_ED_TIME);
1266c92544dSBjoern A. Zeeb else
1276c92544dSBjoern A. Zeeb mt76_clear(dev, MT_MIB_CTL, MT_MIB_CTL_ED_TIME);
1286c92544dSBjoern A. Zeeb
1296c92544dSBjoern A. Zeeb dev->ed_strict_mode = 0xff;
1306c92544dSBjoern A. Zeeb dev->ed_strong_signal = 0;
1316c92544dSBjoern A. Zeeb dev->ed_time = ktime_get_boottime();
1326c92544dSBjoern A. Zeeb
1336c92544dSBjoern A. Zeeb mt7603_edcca_set_strict(dev, false);
1346c92544dSBjoern A. Zeeb }
1356c92544dSBjoern A. Zeeb
1366c92544dSBjoern A. Zeeb static int
mt7603_set_channel(struct ieee80211_hw * hw,struct cfg80211_chan_def * def)1376c92544dSBjoern A. Zeeb mt7603_set_channel(struct ieee80211_hw *hw, struct cfg80211_chan_def *def)
1386c92544dSBjoern A. Zeeb {
1396c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
1406c92544dSBjoern A. Zeeb u8 *rssi_data = (u8 *)dev->mt76.eeprom.data;
1416c92544dSBjoern A. Zeeb int idx, ret;
1426c92544dSBjoern A. Zeeb u8 bw = MT_BW_20;
1436c92544dSBjoern A. Zeeb bool failed = false;
1446c92544dSBjoern A. Zeeb
1456c92544dSBjoern A. Zeeb ieee80211_stop_queues(hw);
1466c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&dev->mphy.mac_work);
1476c92544dSBjoern A. Zeeb tasklet_disable(&dev->mt76.pre_tbtt_tasklet);
1486c92544dSBjoern A. Zeeb
1496c92544dSBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
1506c92544dSBjoern A. Zeeb set_bit(MT76_RESET, &dev->mphy.state);
1516c92544dSBjoern A. Zeeb
1526c92544dSBjoern A. Zeeb mt7603_beacon_set_timer(dev, -1, 0);
1536c92544dSBjoern A. Zeeb mt76_set_channel(&dev->mphy);
1546c92544dSBjoern A. Zeeb mt7603_mac_stop(dev);
1556c92544dSBjoern A. Zeeb
1566c92544dSBjoern A. Zeeb if (def->width == NL80211_CHAN_WIDTH_40)
1576c92544dSBjoern A. Zeeb bw = MT_BW_40;
1586c92544dSBjoern A. Zeeb
1596c92544dSBjoern A. Zeeb dev->mphy.chandef = *def;
1606c92544dSBjoern A. Zeeb mt76_rmw_field(dev, MT_AGG_BWCR, MT_AGG_BWCR_BW, bw);
1616c92544dSBjoern A. Zeeb ret = mt7603_mcu_set_channel(dev);
1626c92544dSBjoern A. Zeeb if (ret) {
1636c92544dSBjoern A. Zeeb failed = true;
1646c92544dSBjoern A. Zeeb goto out;
1656c92544dSBjoern A. Zeeb }
1666c92544dSBjoern A. Zeeb
1676c92544dSBjoern A. Zeeb if (def->chan->band == NL80211_BAND_5GHZ) {
1686c92544dSBjoern A. Zeeb idx = 1;
1696c92544dSBjoern A. Zeeb rssi_data += MT_EE_RSSI_OFFSET_5G;
1706c92544dSBjoern A. Zeeb } else {
1716c92544dSBjoern A. Zeeb idx = 0;
1726c92544dSBjoern A. Zeeb rssi_data += MT_EE_RSSI_OFFSET_2G;
1736c92544dSBjoern A. Zeeb }
1746c92544dSBjoern A. Zeeb
1756c92544dSBjoern A. Zeeb memcpy(dev->rssi_offset, rssi_data, sizeof(dev->rssi_offset));
1766c92544dSBjoern A. Zeeb
1776c92544dSBjoern A. Zeeb idx |= (def->chan -
1786c92544dSBjoern A. Zeeb mt76_hw(dev)->wiphy->bands[def->chan->band]->channels) << 1;
1796c92544dSBjoern A. Zeeb mt76_wr(dev, MT_WF_RMAC_CH_FREQ, idx);
1806c92544dSBjoern A. Zeeb mt7603_mac_set_timing(dev);
1816c92544dSBjoern A. Zeeb mt7603_mac_start(dev);
1826c92544dSBjoern A. Zeeb
1836c92544dSBjoern A. Zeeb clear_bit(MT76_RESET, &dev->mphy.state);
1846c92544dSBjoern A. Zeeb
1856c92544dSBjoern A. Zeeb mt76_txq_schedule_all(&dev->mphy);
1866c92544dSBjoern A. Zeeb
1876c92544dSBjoern A. Zeeb ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work,
1886c92544dSBjoern A. Zeeb msecs_to_jiffies(MT7603_WATCHDOG_TIME));
1896c92544dSBjoern A. Zeeb
1906c92544dSBjoern A. Zeeb /* reset channel stats */
1916c92544dSBjoern A. Zeeb mt76_clear(dev, MT_MIB_CTL, MT_MIB_CTL_READ_CLR_DIS);
1926c92544dSBjoern A. Zeeb mt76_set(dev, MT_MIB_CTL,
1936c92544dSBjoern A. Zeeb MT_MIB_CTL_CCA_NAV_TX | MT_MIB_CTL_PSCCA_TIME);
1946c92544dSBjoern A. Zeeb mt76_rr(dev, MT_MIB_STAT_CCA);
1956c92544dSBjoern A. Zeeb mt7603_cca_stats_reset(dev);
1966c92544dSBjoern A. Zeeb
1976c92544dSBjoern A. Zeeb dev->mphy.survey_time = ktime_get_boottime();
1986c92544dSBjoern A. Zeeb
1996c92544dSBjoern A. Zeeb mt7603_init_edcca(dev);
2006c92544dSBjoern A. Zeeb
2016c92544dSBjoern A. Zeeb out:
2026c92544dSBjoern A. Zeeb if (!(mt76_hw(dev)->conf.flags & IEEE80211_CONF_OFFCHANNEL))
2036c92544dSBjoern A. Zeeb mt7603_beacon_set_timer(dev, -1, dev->mt76.beacon_int);
2046c92544dSBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
2056c92544dSBjoern A. Zeeb
2066c92544dSBjoern A. Zeeb tasklet_enable(&dev->mt76.pre_tbtt_tasklet);
2076c92544dSBjoern A. Zeeb
2086c92544dSBjoern A. Zeeb if (failed)
2096c92544dSBjoern A. Zeeb mt7603_mac_work(&dev->mphy.mac_work.work);
2106c92544dSBjoern A. Zeeb
2116c92544dSBjoern A. Zeeb ieee80211_wake_queues(hw);
2126c92544dSBjoern A. Zeeb
2136c92544dSBjoern A. Zeeb return ret;
2146c92544dSBjoern A. Zeeb }
2156c92544dSBjoern A. Zeeb
mt7603_set_sar_specs(struct ieee80211_hw * hw,const struct cfg80211_sar_specs * sar)2166c92544dSBjoern A. Zeeb static int mt7603_set_sar_specs(struct ieee80211_hw *hw,
2176c92544dSBjoern A. Zeeb const struct cfg80211_sar_specs *sar)
2186c92544dSBjoern A. Zeeb {
2196c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
2206c92544dSBjoern A. Zeeb struct mt76_phy *mphy = &dev->mphy;
2216c92544dSBjoern A. Zeeb int err;
2226c92544dSBjoern A. Zeeb
2236c92544dSBjoern A. Zeeb if (!cfg80211_chandef_valid(&mphy->chandef))
2246c92544dSBjoern A. Zeeb return -EINVAL;
2256c92544dSBjoern A. Zeeb
2266c92544dSBjoern A. Zeeb err = mt76_init_sar_power(hw, sar);
2276c92544dSBjoern A. Zeeb if (err)
2286c92544dSBjoern A. Zeeb return err;
2296c92544dSBjoern A. Zeeb
2306c92544dSBjoern A. Zeeb return mt7603_set_channel(hw, &mphy->chandef);
2316c92544dSBjoern A. Zeeb }
2326c92544dSBjoern A. Zeeb
2336c92544dSBjoern A. Zeeb static int
mt7603_config(struct ieee80211_hw * hw,u32 changed)2346c92544dSBjoern A. Zeeb mt7603_config(struct ieee80211_hw *hw, u32 changed)
2356c92544dSBjoern A. Zeeb {
2366c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
2376c92544dSBjoern A. Zeeb int ret = 0;
2386c92544dSBjoern A. Zeeb
2396c92544dSBjoern A. Zeeb if (changed & (IEEE80211_CONF_CHANGE_CHANNEL |
2406c92544dSBjoern A. Zeeb IEEE80211_CONF_CHANGE_POWER))
2416c92544dSBjoern A. Zeeb ret = mt7603_set_channel(hw, &hw->conf.chandef);
2426c92544dSBjoern A. Zeeb
2436c92544dSBjoern A. Zeeb if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2446c92544dSBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
2456c92544dSBjoern A. Zeeb
2466c92544dSBjoern A. Zeeb if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
2476c92544dSBjoern A. Zeeb dev->rxfilter |= MT_WF_RFCR_DROP_OTHER_UC;
2486c92544dSBjoern A. Zeeb else
2496c92544dSBjoern A. Zeeb dev->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_UC;
2506c92544dSBjoern A. Zeeb
2516c92544dSBjoern A. Zeeb mt76_wr(dev, MT_WF_RFCR, dev->rxfilter);
2526c92544dSBjoern A. Zeeb
2536c92544dSBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
2546c92544dSBjoern A. Zeeb }
2556c92544dSBjoern A. Zeeb
2566c92544dSBjoern A. Zeeb return ret;
2576c92544dSBjoern A. Zeeb }
2586c92544dSBjoern A. Zeeb
2596c92544dSBjoern A. Zeeb static void
mt7603_configure_filter(struct ieee80211_hw * hw,unsigned int changed_flags,unsigned int * total_flags,u64 multicast)2606c92544dSBjoern A. Zeeb mt7603_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
2616c92544dSBjoern A. Zeeb unsigned int *total_flags, u64 multicast)
2626c92544dSBjoern A. Zeeb {
2636c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
2646c92544dSBjoern A. Zeeb u32 flags = 0;
2656c92544dSBjoern A. Zeeb
2666c92544dSBjoern A. Zeeb #define MT76_FILTER(_flag, _hw) do { \
2676c92544dSBjoern A. Zeeb flags |= *total_flags & FIF_##_flag; \
2686c92544dSBjoern A. Zeeb dev->rxfilter &= ~(_hw); \
2696c92544dSBjoern A. Zeeb dev->rxfilter |= !(flags & FIF_##_flag) * (_hw); \
2706c92544dSBjoern A. Zeeb } while (0)
2716c92544dSBjoern A. Zeeb
2726c92544dSBjoern A. Zeeb dev->rxfilter &= ~(MT_WF_RFCR_DROP_OTHER_BSS |
2736c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_OTHER_BEACON |
2746c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_FRAME_REPORT |
2756c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_PROBEREQ |
2766c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_MCAST_FILTERED |
2776c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_MCAST |
2786c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_BCAST |
2796c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_DUPLICATE |
2806c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_A2_BSSID |
2816c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_UNWANTED_CTL |
2826c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_STBC_MULTI);
2836c92544dSBjoern A. Zeeb
2846c92544dSBjoern A. Zeeb MT76_FILTER(OTHER_BSS, MT_WF_RFCR_DROP_OTHER_TIM |
2856c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_A3_MAC |
2866c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_A3_BSSID);
2876c92544dSBjoern A. Zeeb
2886c92544dSBjoern A. Zeeb MT76_FILTER(FCSFAIL, MT_WF_RFCR_DROP_FCSFAIL);
2896c92544dSBjoern A. Zeeb
2906c92544dSBjoern A. Zeeb MT76_FILTER(CONTROL, MT_WF_RFCR_DROP_CTS |
2916c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_RTS |
2926c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_CTL_RSV |
2936c92544dSBjoern A. Zeeb MT_WF_RFCR_DROP_NDPA);
2946c92544dSBjoern A. Zeeb
2956c92544dSBjoern A. Zeeb *total_flags = flags;
2966c92544dSBjoern A. Zeeb mt76_wr(dev, MT_WF_RFCR, dev->rxfilter);
2976c92544dSBjoern A. Zeeb }
2986c92544dSBjoern A. Zeeb
2996c92544dSBjoern A. Zeeb static void
mt7603_bss_info_changed(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * info,u64 changed)3006c92544dSBjoern A. Zeeb mt7603_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3016c92544dSBjoern A. Zeeb struct ieee80211_bss_conf *info, u64 changed)
3026c92544dSBjoern A. Zeeb {
3036c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
3046c92544dSBjoern A. Zeeb struct mt7603_vif *mvif = (struct mt7603_vif *)vif->drv_priv;
3056c92544dSBjoern A. Zeeb
3066c92544dSBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
3076c92544dSBjoern A. Zeeb
3086c92544dSBjoern A. Zeeb if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BSSID)) {
3096c92544dSBjoern A. Zeeb if (vif->cfg.assoc || vif->cfg.ibss_joined) {
3106c92544dSBjoern A. Zeeb mt76_wr(dev, MT_BSSID0(mvif->idx),
3116c92544dSBjoern A. Zeeb get_unaligned_le32(info->bssid));
3126c92544dSBjoern A. Zeeb mt76_wr(dev, MT_BSSID1(mvif->idx),
3136c92544dSBjoern A. Zeeb (get_unaligned_le16(info->bssid + 4) |
3146c92544dSBjoern A. Zeeb MT_BSSID1_VALID));
3156c92544dSBjoern A. Zeeb } else {
3166c92544dSBjoern A. Zeeb mt76_wr(dev, MT_BSSID0(mvif->idx), 0);
3176c92544dSBjoern A. Zeeb mt76_wr(dev, MT_BSSID1(mvif->idx), 0);
3186c92544dSBjoern A. Zeeb }
3196c92544dSBjoern A. Zeeb }
3206c92544dSBjoern A. Zeeb
3216c92544dSBjoern A. Zeeb if (changed & BSS_CHANGED_ERP_SLOT) {
3226c92544dSBjoern A. Zeeb int slottime = info->use_short_slot ? 9 : 20;
3236c92544dSBjoern A. Zeeb
3246c92544dSBjoern A. Zeeb if (slottime != dev->slottime) {
3256c92544dSBjoern A. Zeeb dev->slottime = slottime;
3266c92544dSBjoern A. Zeeb mt7603_mac_set_timing(dev);
3276c92544dSBjoern A. Zeeb }
3286c92544dSBjoern A. Zeeb }
3296c92544dSBjoern A. Zeeb
3306c92544dSBjoern A. Zeeb if (changed & (BSS_CHANGED_BEACON_ENABLED | BSS_CHANGED_BEACON_INT)) {
3316c92544dSBjoern A. Zeeb int beacon_int = !!info->enable_beacon * info->beacon_int;
3326c92544dSBjoern A. Zeeb
3336c92544dSBjoern A. Zeeb tasklet_disable(&dev->mt76.pre_tbtt_tasklet);
3346c92544dSBjoern A. Zeeb mt7603_beacon_set_timer(dev, mvif->idx, beacon_int);
3356c92544dSBjoern A. Zeeb tasklet_enable(&dev->mt76.pre_tbtt_tasklet);
3366c92544dSBjoern A. Zeeb }
3376c92544dSBjoern A. Zeeb
3386c92544dSBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
3396c92544dSBjoern A. Zeeb }
3406c92544dSBjoern A. Zeeb
3416c92544dSBjoern A. Zeeb int
mt7603_sta_add(struct mt76_dev * mdev,struct ieee80211_vif * vif,struct ieee80211_sta * sta)3426c92544dSBjoern A. Zeeb mt7603_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
3436c92544dSBjoern A. Zeeb struct ieee80211_sta *sta)
3446c92544dSBjoern A. Zeeb {
3456c92544dSBjoern A. Zeeb struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76);
3466c92544dSBjoern A. Zeeb struct mt7603_sta *msta = (struct mt7603_sta *)sta->drv_priv;
3476c92544dSBjoern A. Zeeb struct mt7603_vif *mvif = (struct mt7603_vif *)vif->drv_priv;
3486c92544dSBjoern A. Zeeb int idx;
3496c92544dSBjoern A. Zeeb int ret = 0;
3506c92544dSBjoern A. Zeeb
3516c92544dSBjoern A. Zeeb idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7603_WTBL_STA - 1);
3526c92544dSBjoern A. Zeeb if (idx < 0)
3536c92544dSBjoern A. Zeeb return -ENOSPC;
3546c92544dSBjoern A. Zeeb
355*cbb3ec25SBjoern A. Zeeb INIT_LIST_HEAD(&msta->wcid.poll_list);
3566c92544dSBjoern A. Zeeb __skb_queue_head_init(&msta->psq);
3576c92544dSBjoern A. Zeeb msta->ps = ~0;
3586c92544dSBjoern A. Zeeb msta->smps = ~0;
3596c92544dSBjoern A. Zeeb msta->wcid.sta = 1;
3606c92544dSBjoern A. Zeeb msta->wcid.idx = idx;
361*cbb3ec25SBjoern A. Zeeb msta->vif = mvif;
3626c92544dSBjoern A. Zeeb mt7603_wtbl_init(dev, idx, mvif->idx, sta->addr);
3636c92544dSBjoern A. Zeeb mt7603_wtbl_set_ps(dev, msta, false);
3646c92544dSBjoern A. Zeeb
3656c92544dSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_AP)
3666c92544dSBjoern A. Zeeb set_bit(MT_WCID_FLAG_CHECK_PS, &msta->wcid.flags);
3676c92544dSBjoern A. Zeeb
3686c92544dSBjoern A. Zeeb return ret;
3696c92544dSBjoern A. Zeeb }
3706c92544dSBjoern A. Zeeb
3716c92544dSBjoern A. Zeeb void
mt7603_sta_assoc(struct mt76_dev * mdev,struct ieee80211_vif * vif,struct ieee80211_sta * sta)3726c92544dSBjoern A. Zeeb mt7603_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif,
3736c92544dSBjoern A. Zeeb struct ieee80211_sta *sta)
3746c92544dSBjoern A. Zeeb {
3756c92544dSBjoern A. Zeeb struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76);
3766c92544dSBjoern A. Zeeb
3776c92544dSBjoern A. Zeeb mt7603_wtbl_update_cap(dev, sta);
3786c92544dSBjoern A. Zeeb }
3796c92544dSBjoern A. Zeeb
3806c92544dSBjoern A. Zeeb void
mt7603_sta_remove(struct mt76_dev * mdev,struct ieee80211_vif * vif,struct ieee80211_sta * sta)3816c92544dSBjoern A. Zeeb mt7603_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
3826c92544dSBjoern A. Zeeb struct ieee80211_sta *sta)
3836c92544dSBjoern A. Zeeb {
3846c92544dSBjoern A. Zeeb struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76);
385*cbb3ec25SBjoern A. Zeeb struct mt7603_vif *mvif = (struct mt7603_vif *)vif->drv_priv;
3866c92544dSBjoern A. Zeeb struct mt7603_sta *msta = (struct mt7603_sta *)sta->drv_priv;
3876c92544dSBjoern A. Zeeb struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
3886c92544dSBjoern A. Zeeb
3896c92544dSBjoern A. Zeeb spin_lock_bh(&dev->ps_lock);
3906c92544dSBjoern A. Zeeb __skb_queue_purge(&msta->psq);
391*cbb3ec25SBjoern A. Zeeb mt7603_filter_tx(dev, mvif->idx, wcid->idx, true);
3926c92544dSBjoern A. Zeeb spin_unlock_bh(&dev->ps_lock);
3936c92544dSBjoern A. Zeeb
394*cbb3ec25SBjoern A. Zeeb spin_lock_bh(&mdev->sta_poll_lock);
395*cbb3ec25SBjoern A. Zeeb if (!list_empty(&msta->wcid.poll_list))
396*cbb3ec25SBjoern A. Zeeb list_del_init(&msta->wcid.poll_list);
397*cbb3ec25SBjoern A. Zeeb spin_unlock_bh(&mdev->sta_poll_lock);
3986c92544dSBjoern A. Zeeb
3996c92544dSBjoern A. Zeeb mt7603_wtbl_clear(dev, wcid->idx);
4006c92544dSBjoern A. Zeeb }
4016c92544dSBjoern A. Zeeb
4026c92544dSBjoern A. Zeeb static void
mt7603_ps_tx_list(struct mt7603_dev * dev,struct sk_buff_head * list)4036c92544dSBjoern A. Zeeb mt7603_ps_tx_list(struct mt7603_dev *dev, struct sk_buff_head *list)
4046c92544dSBjoern A. Zeeb {
4056c92544dSBjoern A. Zeeb struct sk_buff *skb;
4066c92544dSBjoern A. Zeeb
4076c92544dSBjoern A. Zeeb while ((skb = __skb_dequeue(list)) != NULL) {
4086c92544dSBjoern A. Zeeb int qid = skb_get_queue_mapping(skb);
4096c92544dSBjoern A. Zeeb
4106c92544dSBjoern A. Zeeb mt76_tx_queue_skb_raw(dev, dev->mphy.q_tx[qid], skb, 0);
4116c92544dSBjoern A. Zeeb }
4126c92544dSBjoern A. Zeeb }
4136c92544dSBjoern A. Zeeb
4146c92544dSBjoern A. Zeeb void
mt7603_sta_ps(struct mt76_dev * mdev,struct ieee80211_sta * sta,bool ps)4156c92544dSBjoern A. Zeeb mt7603_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps)
4166c92544dSBjoern A. Zeeb {
4176c92544dSBjoern A. Zeeb struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76);
4186c92544dSBjoern A. Zeeb struct mt7603_sta *msta = (struct mt7603_sta *)sta->drv_priv;
4196c92544dSBjoern A. Zeeb struct sk_buff_head list;
4206c92544dSBjoern A. Zeeb
4216c92544dSBjoern A. Zeeb mt76_stop_tx_queues(&dev->mphy, sta, true);
4226c92544dSBjoern A. Zeeb mt7603_wtbl_set_ps(dev, msta, ps);
4236c92544dSBjoern A. Zeeb if (ps)
4246c92544dSBjoern A. Zeeb return;
4256c92544dSBjoern A. Zeeb
4266c92544dSBjoern A. Zeeb __skb_queue_head_init(&list);
4276c92544dSBjoern A. Zeeb
4286c92544dSBjoern A. Zeeb spin_lock_bh(&dev->ps_lock);
4296c92544dSBjoern A. Zeeb skb_queue_splice_tail_init(&msta->psq, &list);
4306c92544dSBjoern A. Zeeb spin_unlock_bh(&dev->ps_lock);
4316c92544dSBjoern A. Zeeb
4326c92544dSBjoern A. Zeeb mt7603_ps_tx_list(dev, &list);
4336c92544dSBjoern A. Zeeb }
4346c92544dSBjoern A. Zeeb
4356c92544dSBjoern A. Zeeb static void
mt7603_ps_set_more_data(struct sk_buff * skb)4366c92544dSBjoern A. Zeeb mt7603_ps_set_more_data(struct sk_buff *skb)
4376c92544dSBjoern A. Zeeb {
4386c92544dSBjoern A. Zeeb struct ieee80211_hdr *hdr;
4396c92544dSBjoern A. Zeeb
4406c92544dSBjoern A. Zeeb hdr = (struct ieee80211_hdr *)&skb->data[MT_TXD_SIZE];
4416c92544dSBjoern A. Zeeb hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
4426c92544dSBjoern A. Zeeb }
4436c92544dSBjoern A. Zeeb
4446c92544dSBjoern A. Zeeb static void
mt7603_release_buffered_frames(struct ieee80211_hw * hw,struct ieee80211_sta * sta,u16 tids,int nframes,enum ieee80211_frame_release_type reason,bool more_data)4456c92544dSBjoern A. Zeeb mt7603_release_buffered_frames(struct ieee80211_hw *hw,
4466c92544dSBjoern A. Zeeb struct ieee80211_sta *sta,
4476c92544dSBjoern A. Zeeb u16 tids, int nframes,
4486c92544dSBjoern A. Zeeb enum ieee80211_frame_release_type reason,
4496c92544dSBjoern A. Zeeb bool more_data)
4506c92544dSBjoern A. Zeeb {
4516c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
4526c92544dSBjoern A. Zeeb struct mt7603_sta *msta = (struct mt7603_sta *)sta->drv_priv;
4536c92544dSBjoern A. Zeeb struct sk_buff_head list;
4546c92544dSBjoern A. Zeeb struct sk_buff *skb, *tmp;
4556c92544dSBjoern A. Zeeb
4566c92544dSBjoern A. Zeeb __skb_queue_head_init(&list);
4576c92544dSBjoern A. Zeeb
4586c92544dSBjoern A. Zeeb mt7603_wtbl_set_ps(dev, msta, false);
4596c92544dSBjoern A. Zeeb
4606c92544dSBjoern A. Zeeb spin_lock_bh(&dev->ps_lock);
4616c92544dSBjoern A. Zeeb skb_queue_walk_safe(&msta->psq, skb, tmp) {
4626c92544dSBjoern A. Zeeb if (!nframes)
4636c92544dSBjoern A. Zeeb break;
4646c92544dSBjoern A. Zeeb
4656c92544dSBjoern A. Zeeb if (!(tids & BIT(skb->priority)))
4666c92544dSBjoern A. Zeeb continue;
4676c92544dSBjoern A. Zeeb
4686c92544dSBjoern A. Zeeb skb_set_queue_mapping(skb, MT_TXQ_PSD);
4696c92544dSBjoern A. Zeeb __skb_unlink(skb, &msta->psq);
4706c92544dSBjoern A. Zeeb mt7603_ps_set_more_data(skb);
4716c92544dSBjoern A. Zeeb __skb_queue_tail(&list, skb);
4726c92544dSBjoern A. Zeeb nframes--;
4736c92544dSBjoern A. Zeeb }
4746c92544dSBjoern A. Zeeb spin_unlock_bh(&dev->ps_lock);
4756c92544dSBjoern A. Zeeb
4766c92544dSBjoern A. Zeeb if (!skb_queue_empty(&list))
4776c92544dSBjoern A. Zeeb ieee80211_sta_eosp(sta);
4786c92544dSBjoern A. Zeeb
4796c92544dSBjoern A. Zeeb mt7603_ps_tx_list(dev, &list);
4806c92544dSBjoern A. Zeeb
4816c92544dSBjoern A. Zeeb if (nframes)
4826c92544dSBjoern A. Zeeb mt76_release_buffered_frames(hw, sta, tids, nframes, reason,
4836c92544dSBjoern A. Zeeb more_data);
4846c92544dSBjoern A. Zeeb }
4856c92544dSBjoern A. Zeeb
4866c92544dSBjoern A. Zeeb static int
mt7603_set_key(struct ieee80211_hw * hw,enum set_key_cmd cmd,struct ieee80211_vif * vif,struct ieee80211_sta * sta,struct ieee80211_key_conf * key)4876c92544dSBjoern A. Zeeb mt7603_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4886c92544dSBjoern A. Zeeb struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4896c92544dSBjoern A. Zeeb struct ieee80211_key_conf *key)
4906c92544dSBjoern A. Zeeb {
4916c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
4926c92544dSBjoern A. Zeeb struct mt7603_vif *mvif = (struct mt7603_vif *)vif->drv_priv;
4936c92544dSBjoern A. Zeeb struct mt7603_sta *msta = sta ? (struct mt7603_sta *)sta->drv_priv :
4946c92544dSBjoern A. Zeeb &mvif->sta;
4956c92544dSBjoern A. Zeeb struct mt76_wcid *wcid = &msta->wcid;
4966c92544dSBjoern A. Zeeb int idx = key->keyidx;
4976c92544dSBjoern A. Zeeb
4986c92544dSBjoern A. Zeeb /* fall back to sw encryption for unsupported ciphers */
4996c92544dSBjoern A. Zeeb switch (key->cipher) {
5006c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP:
5016c92544dSBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP:
5026c92544dSBjoern A. Zeeb break;
5036c92544dSBjoern A. Zeeb default:
5046c92544dSBjoern A. Zeeb return -EOPNOTSUPP;
5056c92544dSBjoern A. Zeeb }
5066c92544dSBjoern A. Zeeb
5076c92544dSBjoern A. Zeeb /*
5086c92544dSBjoern A. Zeeb * The hardware does not support per-STA RX GTK, fall back
5096c92544dSBjoern A. Zeeb * to software mode for these.
5106c92544dSBjoern A. Zeeb */
5116c92544dSBjoern A. Zeeb if ((vif->type == NL80211_IFTYPE_ADHOC ||
5126c92544dSBjoern A. Zeeb vif->type == NL80211_IFTYPE_MESH_POINT) &&
5136c92544dSBjoern A. Zeeb (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
5146c92544dSBjoern A. Zeeb key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
5156c92544dSBjoern A. Zeeb !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
5166c92544dSBjoern A. Zeeb return -EOPNOTSUPP;
5176c92544dSBjoern A. Zeeb
518*cbb3ec25SBjoern A. Zeeb if (cmd != SET_KEY) {
5196c92544dSBjoern A. Zeeb if (idx == wcid->hw_key_idx)
5206c92544dSBjoern A. Zeeb wcid->hw_key_idx = -1;
5216c92544dSBjoern A. Zeeb
522*cbb3ec25SBjoern A. Zeeb return 0;
5236c92544dSBjoern A. Zeeb }
524*cbb3ec25SBjoern A. Zeeb
525*cbb3ec25SBjoern A. Zeeb key->hw_key_idx = wcid->idx;
526*cbb3ec25SBjoern A. Zeeb wcid->hw_key_idx = idx;
5276c92544dSBjoern A. Zeeb mt76_wcid_key_setup(&dev->mt76, wcid, key);
5286c92544dSBjoern A. Zeeb
5296c92544dSBjoern A. Zeeb return mt7603_wtbl_set_key(dev, wcid->idx, key);
5306c92544dSBjoern A. Zeeb }
5316c92544dSBjoern A. Zeeb
5326c92544dSBjoern A. Zeeb static int
mt7603_conf_tx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,unsigned int link_id,u16 queue,const struct ieee80211_tx_queue_params * params)5336c92544dSBjoern A. Zeeb mt7603_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5346c92544dSBjoern A. Zeeb unsigned int link_id, u16 queue,
5356c92544dSBjoern A. Zeeb const struct ieee80211_tx_queue_params *params)
5366c92544dSBjoern A. Zeeb {
5376c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
5386c92544dSBjoern A. Zeeb u16 cw_min = (1 << 5) - 1;
5396c92544dSBjoern A. Zeeb u16 cw_max = (1 << 10) - 1;
5406c92544dSBjoern A. Zeeb u32 val;
5416c92544dSBjoern A. Zeeb
5426c92544dSBjoern A. Zeeb queue = dev->mphy.q_tx[queue]->hw_idx;
5436c92544dSBjoern A. Zeeb
5446c92544dSBjoern A. Zeeb if (params->cw_min)
5456c92544dSBjoern A. Zeeb cw_min = params->cw_min;
5466c92544dSBjoern A. Zeeb if (params->cw_max)
5476c92544dSBjoern A. Zeeb cw_max = params->cw_max;
5486c92544dSBjoern A. Zeeb
5496c92544dSBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
5506c92544dSBjoern A. Zeeb mt7603_mac_stop(dev);
5516c92544dSBjoern A. Zeeb
5526c92544dSBjoern A. Zeeb val = mt76_rr(dev, MT_WMM_TXOP(queue));
5536c92544dSBjoern A. Zeeb val &= ~(MT_WMM_TXOP_MASK << MT_WMM_TXOP_SHIFT(queue));
5546c92544dSBjoern A. Zeeb val |= params->txop << MT_WMM_TXOP_SHIFT(queue);
5556c92544dSBjoern A. Zeeb mt76_wr(dev, MT_WMM_TXOP(queue), val);
5566c92544dSBjoern A. Zeeb
5576c92544dSBjoern A. Zeeb val = mt76_rr(dev, MT_WMM_AIFSN);
5586c92544dSBjoern A. Zeeb val &= ~(MT_WMM_AIFSN_MASK << MT_WMM_AIFSN_SHIFT(queue));
5596c92544dSBjoern A. Zeeb val |= params->aifs << MT_WMM_AIFSN_SHIFT(queue);
5606c92544dSBjoern A. Zeeb mt76_wr(dev, MT_WMM_AIFSN, val);
5616c92544dSBjoern A. Zeeb
5626c92544dSBjoern A. Zeeb val = mt76_rr(dev, MT_WMM_CWMIN);
5636c92544dSBjoern A. Zeeb val &= ~(MT_WMM_CWMIN_MASK << MT_WMM_CWMIN_SHIFT(queue));
5646c92544dSBjoern A. Zeeb val |= cw_min << MT_WMM_CWMIN_SHIFT(queue);
5656c92544dSBjoern A. Zeeb mt76_wr(dev, MT_WMM_CWMIN, val);
5666c92544dSBjoern A. Zeeb
5676c92544dSBjoern A. Zeeb val = mt76_rr(dev, MT_WMM_CWMAX(queue));
5686c92544dSBjoern A. Zeeb val &= ~(MT_WMM_CWMAX_MASK << MT_WMM_CWMAX_SHIFT(queue));
5696c92544dSBjoern A. Zeeb val |= cw_max << MT_WMM_CWMAX_SHIFT(queue);
5706c92544dSBjoern A. Zeeb mt76_wr(dev, MT_WMM_CWMAX(queue), val);
5716c92544dSBjoern A. Zeeb
5726c92544dSBjoern A. Zeeb mt7603_mac_start(dev);
5736c92544dSBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
5746c92544dSBjoern A. Zeeb
5756c92544dSBjoern A. Zeeb return 0;
5766c92544dSBjoern A. Zeeb }
5776c92544dSBjoern A. Zeeb
5786c92544dSBjoern A. Zeeb static void
mt7603_flush(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u32 queues,bool drop)5796c92544dSBjoern A. Zeeb mt7603_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5806c92544dSBjoern A. Zeeb u32 queues, bool drop)
5816c92544dSBjoern A. Zeeb {
5826c92544dSBjoern A. Zeeb }
5836c92544dSBjoern A. Zeeb
5846c92544dSBjoern A. Zeeb static int
mt7603_ampdu_action(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_ampdu_params * params)5856c92544dSBjoern A. Zeeb mt7603_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5866c92544dSBjoern A. Zeeb struct ieee80211_ampdu_params *params)
5876c92544dSBjoern A. Zeeb {
5886c92544dSBjoern A. Zeeb enum ieee80211_ampdu_mlme_action action = params->action;
5896c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
5906c92544dSBjoern A. Zeeb struct ieee80211_sta *sta = params->sta;
5916c92544dSBjoern A. Zeeb struct ieee80211_txq *txq = sta->txq[params->tid];
5926c92544dSBjoern A. Zeeb struct mt7603_sta *msta = (struct mt7603_sta *)sta->drv_priv;
5936c92544dSBjoern A. Zeeb u16 tid = params->tid;
5946c92544dSBjoern A. Zeeb u16 ssn = params->ssn;
5956c92544dSBjoern A. Zeeb u8 ba_size = params->buf_size;
5966c92544dSBjoern A. Zeeb struct mt76_txq *mtxq;
5976c92544dSBjoern A. Zeeb int ret = 0;
5986c92544dSBjoern A. Zeeb
5996c92544dSBjoern A. Zeeb if (!txq)
6006c92544dSBjoern A. Zeeb return -EINVAL;
6016c92544dSBjoern A. Zeeb
6026c92544dSBjoern A. Zeeb mtxq = (struct mt76_txq *)txq->drv_priv;
6036c92544dSBjoern A. Zeeb
6046c92544dSBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
6056c92544dSBjoern A. Zeeb switch (action) {
6066c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_RX_START:
6076c92544dSBjoern A. Zeeb mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, ssn,
6086c92544dSBjoern A. Zeeb params->buf_size);
6096c92544dSBjoern A. Zeeb mt7603_mac_rx_ba_reset(dev, sta->addr, tid);
6106c92544dSBjoern A. Zeeb break;
6116c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_RX_STOP:
6126c92544dSBjoern A. Zeeb mt76_rx_aggr_stop(&dev->mt76, &msta->wcid, tid);
6136c92544dSBjoern A. Zeeb break;
6146c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_OPERATIONAL:
6156c92544dSBjoern A. Zeeb mtxq->aggr = true;
6166c92544dSBjoern A. Zeeb mtxq->send_bar = false;
6176c92544dSBjoern A. Zeeb mt7603_mac_tx_ba_reset(dev, msta->wcid.idx, tid, ba_size);
6186c92544dSBjoern A. Zeeb break;
6196c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_STOP_FLUSH:
6206c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6216c92544dSBjoern A. Zeeb mtxq->aggr = false;
6226c92544dSBjoern A. Zeeb mt7603_mac_tx_ba_reset(dev, msta->wcid.idx, tid, -1);
6236c92544dSBjoern A. Zeeb break;
6246c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_START:
6256c92544dSBjoern A. Zeeb mtxq->agg_ssn = IEEE80211_SN_TO_SEQ(ssn);
6266c92544dSBjoern A. Zeeb ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;
6276c92544dSBjoern A. Zeeb break;
6286c92544dSBjoern A. Zeeb case IEEE80211_AMPDU_TX_STOP_CONT:
6296c92544dSBjoern A. Zeeb mtxq->aggr = false;
6306c92544dSBjoern A. Zeeb mt7603_mac_tx_ba_reset(dev, msta->wcid.idx, tid, -1);
6316c92544dSBjoern A. Zeeb ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
6326c92544dSBjoern A. Zeeb break;
6336c92544dSBjoern A. Zeeb }
6346c92544dSBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
6356c92544dSBjoern A. Zeeb
6366c92544dSBjoern A. Zeeb return ret;
6376c92544dSBjoern A. Zeeb }
6386c92544dSBjoern A. Zeeb
6396c92544dSBjoern A. Zeeb static void
mt7603_sta_rate_tbl_update(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)6406c92544dSBjoern A. Zeeb mt7603_sta_rate_tbl_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6416c92544dSBjoern A. Zeeb struct ieee80211_sta *sta)
6426c92544dSBjoern A. Zeeb {
6436c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
6446c92544dSBjoern A. Zeeb struct mt7603_sta *msta = (struct mt7603_sta *)sta->drv_priv;
6456c92544dSBjoern A. Zeeb struct ieee80211_sta_rates *sta_rates = rcu_dereference(sta->rates);
6466c92544dSBjoern A. Zeeb int i;
6476c92544dSBjoern A. Zeeb
6486c92544dSBjoern A. Zeeb if (!sta_rates)
6496c92544dSBjoern A. Zeeb return;
6506c92544dSBjoern A. Zeeb
6516c92544dSBjoern A. Zeeb spin_lock_bh(&dev->mt76.lock);
6526c92544dSBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(msta->rates); i++) {
6536c92544dSBjoern A. Zeeb msta->rates[i].idx = sta_rates->rate[i].idx;
6546c92544dSBjoern A. Zeeb msta->rates[i].count = sta_rates->rate[i].count;
6556c92544dSBjoern A. Zeeb msta->rates[i].flags = sta_rates->rate[i].flags;
6566c92544dSBjoern A. Zeeb
6576c92544dSBjoern A. Zeeb if (msta->rates[i].idx < 0 || !msta->rates[i].count)
6586c92544dSBjoern A. Zeeb break;
6596c92544dSBjoern A. Zeeb }
6606c92544dSBjoern A. Zeeb msta->n_rates = i;
6616c92544dSBjoern A. Zeeb mt7603_wtbl_set_rates(dev, msta, NULL, msta->rates);
6626c92544dSBjoern A. Zeeb msta->rate_probe = false;
6636c92544dSBjoern A. Zeeb mt7603_wtbl_set_smps(dev, msta,
6646c92544dSBjoern A. Zeeb sta->deflink.smps_mode == IEEE80211_SMPS_DYNAMIC);
6656c92544dSBjoern A. Zeeb spin_unlock_bh(&dev->mt76.lock);
6666c92544dSBjoern A. Zeeb }
6676c92544dSBjoern A. Zeeb
6686c92544dSBjoern A. Zeeb static void
mt7603_set_coverage_class(struct ieee80211_hw * hw,s16 coverage_class)6696c92544dSBjoern A. Zeeb mt7603_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class)
6706c92544dSBjoern A. Zeeb {
6716c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
6726c92544dSBjoern A. Zeeb
6736c92544dSBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
6746c92544dSBjoern A. Zeeb dev->coverage_class = max_t(s16, coverage_class, 0);
6756c92544dSBjoern A. Zeeb mt7603_mac_set_timing(dev);
6766c92544dSBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
6776c92544dSBjoern A. Zeeb }
6786c92544dSBjoern A. Zeeb
mt7603_tx(struct ieee80211_hw * hw,struct ieee80211_tx_control * control,struct sk_buff * skb)6796c92544dSBjoern A. Zeeb static void mt7603_tx(struct ieee80211_hw *hw,
6806c92544dSBjoern A. Zeeb struct ieee80211_tx_control *control,
6816c92544dSBjoern A. Zeeb struct sk_buff *skb)
6826c92544dSBjoern A. Zeeb {
6836c92544dSBjoern A. Zeeb struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
6846c92544dSBjoern A. Zeeb struct ieee80211_vif *vif = info->control.vif;
6856c92544dSBjoern A. Zeeb struct mt7603_dev *dev = hw->priv;
6866c92544dSBjoern A. Zeeb struct mt76_wcid *wcid = &dev->global_sta.wcid;
6876c92544dSBjoern A. Zeeb
6886c92544dSBjoern A. Zeeb if (control->sta) {
6896c92544dSBjoern A. Zeeb struct mt7603_sta *msta;
6906c92544dSBjoern A. Zeeb
6916c92544dSBjoern A. Zeeb msta = (struct mt7603_sta *)control->sta->drv_priv;
6926c92544dSBjoern A. Zeeb wcid = &msta->wcid;
6936c92544dSBjoern A. Zeeb } else if (vif) {
6946c92544dSBjoern A. Zeeb struct mt7603_vif *mvif;
6956c92544dSBjoern A. Zeeb
6966c92544dSBjoern A. Zeeb mvif = (struct mt7603_vif *)vif->drv_priv;
6976c92544dSBjoern A. Zeeb wcid = &mvif->sta.wcid;
6986c92544dSBjoern A. Zeeb }
6996c92544dSBjoern A. Zeeb
7006c92544dSBjoern A. Zeeb mt76_tx(&dev->mphy, control->sta, wcid, skb);
7016c92544dSBjoern A. Zeeb }
7026c92544dSBjoern A. Zeeb
7036c92544dSBjoern A. Zeeb const struct ieee80211_ops mt7603_ops = {
7046c92544dSBjoern A. Zeeb .tx = mt7603_tx,
7056c92544dSBjoern A. Zeeb .start = mt7603_start,
7066c92544dSBjoern A. Zeeb .stop = mt7603_stop,
7076c92544dSBjoern A. Zeeb .add_interface = mt7603_add_interface,
7086c92544dSBjoern A. Zeeb .remove_interface = mt7603_remove_interface,
7096c92544dSBjoern A. Zeeb .config = mt7603_config,
7106c92544dSBjoern A. Zeeb .configure_filter = mt7603_configure_filter,
7116c92544dSBjoern A. Zeeb .bss_info_changed = mt7603_bss_info_changed,
7126c92544dSBjoern A. Zeeb .sta_state = mt76_sta_state,
7136c92544dSBjoern A. Zeeb .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
7146c92544dSBjoern A. Zeeb .set_key = mt7603_set_key,
7156c92544dSBjoern A. Zeeb .conf_tx = mt7603_conf_tx,
7166c92544dSBjoern A. Zeeb .sw_scan_start = mt76_sw_scan,
7176c92544dSBjoern A. Zeeb .sw_scan_complete = mt76_sw_scan_complete,
7186c92544dSBjoern A. Zeeb .flush = mt7603_flush,
7196c92544dSBjoern A. Zeeb .ampdu_action = mt7603_ampdu_action,
7206c92544dSBjoern A. Zeeb .get_txpower = mt76_get_txpower,
7216c92544dSBjoern A. Zeeb .wake_tx_queue = mt76_wake_tx_queue,
7226c92544dSBjoern A. Zeeb .sta_rate_tbl_update = mt7603_sta_rate_tbl_update,
7236c92544dSBjoern A. Zeeb .release_buffered_frames = mt7603_release_buffered_frames,
7246c92544dSBjoern A. Zeeb .set_coverage_class = mt7603_set_coverage_class,
7256c92544dSBjoern A. Zeeb .set_tim = mt76_set_tim,
7266c92544dSBjoern A. Zeeb .get_survey = mt76_get_survey,
7276c92544dSBjoern A. Zeeb .get_antenna = mt76_get_antenna,
7286c92544dSBjoern A. Zeeb .set_sar_specs = mt7603_set_sar_specs,
7296c92544dSBjoern A. Zeeb };
7306c92544dSBjoern A. Zeeb
7316c92544dSBjoern A. Zeeb MODULE_LICENSE("Dual BSD/GPL");
7326c92544dSBjoern A. Zeeb
mt7603_init(void)7336c92544dSBjoern A. Zeeb static int __init mt7603_init(void)
7346c92544dSBjoern A. Zeeb {
7356c92544dSBjoern A. Zeeb int ret;
7366c92544dSBjoern A. Zeeb
7376c92544dSBjoern A. Zeeb ret = platform_driver_register(&mt76_wmac_driver);
7386c92544dSBjoern A. Zeeb if (ret)
7396c92544dSBjoern A. Zeeb return ret;
7406c92544dSBjoern A. Zeeb
7416c92544dSBjoern A. Zeeb #ifdef CONFIG_PCI
7426c92544dSBjoern A. Zeeb ret = pci_register_driver(&mt7603_pci_driver);
7436c92544dSBjoern A. Zeeb if (ret)
7446c92544dSBjoern A. Zeeb platform_driver_unregister(&mt76_wmac_driver);
7456c92544dSBjoern A. Zeeb #endif
7466c92544dSBjoern A. Zeeb return ret;
7476c92544dSBjoern A. Zeeb }
7486c92544dSBjoern A. Zeeb
mt7603_exit(void)7496c92544dSBjoern A. Zeeb static void __exit mt7603_exit(void)
7506c92544dSBjoern A. Zeeb {
7516c92544dSBjoern A. Zeeb #ifdef CONFIG_PCI
7526c92544dSBjoern A. Zeeb pci_unregister_driver(&mt7603_pci_driver);
7536c92544dSBjoern A. Zeeb #endif
7546c92544dSBjoern A. Zeeb platform_driver_unregister(&mt76_wmac_driver);
7556c92544dSBjoern A. Zeeb }
7566c92544dSBjoern A. Zeeb
7576c92544dSBjoern A. Zeeb module_init(mt7603_init);
7586c92544dSBjoern A. Zeeb module_exit(mt7603_exit);
759