summaryrefslogtreecommitdiffhomepage
path: root/drivers/net/wireless/mediatek/mt76/mac80211.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/mediatek/mt76/mac80211.c')
-rw-r--r--drivers/net/wireless/mediatek/mt76/mac80211.c230
1 files changed, 228 insertions, 2 deletions
diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c
index 75772979f438..4ae5e4715a9c 100644
--- a/drivers/net/wireless/mediatek/mt76/mac80211.c
+++ b/drivers/net/wireless/mediatek/mt76/mac80211.c
@@ -726,6 +726,7 @@ mt76_alloc_device(struct device *pdev, unsigned int size,
INIT_LIST_HEAD(&dev->rxwi_cache);
dev->token_size = dev->drv->token_size;
INIT_DELAYED_WORK(&dev->scan_work, mt76_scan_work);
+ spin_lock_init(&dev->scan_lock);
for (i = 0; i < ARRAY_SIZE(dev->q_rx); i++)
skb_queue_head_init(&dev->rx_skb[i]);
@@ -970,6 +971,9 @@ bool mt76_has_tx_pending(struct mt76_phy *phy)
return true;
}
+ if (atomic_read(&phy->mgmt_tx_pending))
+ return true;
+
return false;
}
EXPORT_SYMBOL_GPL(mt76_has_tx_pending);
@@ -1030,9 +1034,10 @@ int __mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef,
int timeout = HZ / 5;
int ret;
- set_bit(MT76_RESET, &phy->state);
-
mt76_worker_disable(&dev->tx_worker);
+ mt76_txq_schedule_pending(phy);
+
+ set_bit(MT76_RESET, &phy->state);
wait_event_timeout(dev->tx_wait, !mt76_has_tx_pending(phy), timeout);
mt76_update_survey(phy);
@@ -1716,6 +1721,16 @@ void mt76_wcid_cleanup(struct mt76_dev *dev, struct mt76_wcid *wcid)
idr_destroy(&wcid->pktid);
+ /* Remove from sta_poll_list to prevent list corruption after reset.
+ * Without this, mt76_reset_device() reinitializes sta_poll_list but
+ * leaves wcid->poll_list with stale pointers, causing list corruption
+ * when mt76_wcid_add_poll() checks list_empty().
+ */
+ spin_lock_bh(&dev->sta_poll_lock);
+ if (!list_empty(&wcid->poll_list))
+ list_del_init(&wcid->poll_list);
+ spin_unlock_bh(&dev->sta_poll_lock);
+
spin_lock_bh(&phy->tx_lock);
if (!list_empty(&wcid->tx_list))
@@ -2121,3 +2136,214 @@ u16 mt76_select_links(struct ieee80211_vif *vif, int max_active_links)
return sel_links;
}
EXPORT_SYMBOL_GPL(mt76_select_links);
+
+struct mt76_offchannel_cb_data {
+ struct mt76_phy *phy;
+ bool offchannel;
+};
+
+static void
+mt76_offchannel_send_nullfunc(struct mt76_offchannel_cb_data *data,
+ struct ieee80211_vif *vif, int link_id)
+{
+ struct mt76_phy *phy = data->phy;
+ struct ieee80211_tx_info *info;
+ struct ieee80211_sta *sta = NULL;
+ struct ieee80211_hdr *hdr;
+ struct mt76_wcid *wcid;
+ struct sk_buff *skb;
+
+ skb = ieee80211_nullfunc_get(phy->hw, vif, link_id, true);
+ if (!skb)
+ return;
+
+ hdr = (struct ieee80211_hdr *)skb->data;
+ if (data->offchannel)
+ hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
+
+ skb->priority = 7;
+ skb_set_queue_mapping(skb, IEEE80211_AC_VO);
+
+ if (!ieee80211_tx_prepare_skb(phy->hw, vif, skb,
+ phy->main_chandef.chan->band,
+ &sta))
+ return;
+
+ if (sta)
+ wcid = (struct mt76_wcid *)sta->drv_priv;
+ else
+ wcid = ((struct mt76_vif_link *)vif->drv_priv)->wcid;
+
+ if (link_id >= 0) {
+ info = IEEE80211_SKB_CB(skb);
+ info->control.flags &= ~IEEE80211_TX_CTRL_MLO_LINK;
+ info->control.flags |=
+ u32_encode_bits(link_id, IEEE80211_TX_CTRL_MLO_LINK);
+ }
+
+ mt76_tx(phy, sta, wcid, skb);
+}
+
+static void
+mt76_offchannel_notify_iter(void *_data, u8 *mac, struct ieee80211_vif *vif)
+{
+ struct mt76_offchannel_cb_data *data = _data;
+ struct mt76_vif_link *mlink;
+ struct mt76_vif_data *mvif;
+ int link_id;
+
+ if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc)
+ return;
+
+ mlink = (struct mt76_vif_link *)vif->drv_priv;
+ mvif = mlink->mvif;
+
+ if (!ieee80211_vif_is_mld(vif)) {
+ if (mt76_vif_link_phy(mlink) == data->phy) {
+ if (!data->offchannel && mlink->beacon_mon_interval)
+ WRITE_ONCE(mlink->beacon_mon_last, jiffies);
+ mt76_offchannel_send_nullfunc(data, vif, -1);
+ }
+ return;
+ }
+
+ for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
+ if (link_id == mvif->deflink_id)
+ mlink = (struct mt76_vif_link *)vif->drv_priv;
+ else
+ mlink = rcu_dereference(mvif->link[link_id]);
+ if (!mlink)
+ continue;
+ if (mt76_vif_link_phy(mlink) != data->phy)
+ continue;
+
+ if (!data->offchannel && mlink->beacon_mon_interval)
+ WRITE_ONCE(mlink->beacon_mon_last, jiffies);
+
+ mt76_offchannel_send_nullfunc(data, vif, link_id);
+ }
+}
+
+void mt76_offchannel_notify(struct mt76_phy *phy, bool offchannel)
+{
+ struct mt76_offchannel_cb_data data = {
+ .phy = phy,
+ .offchannel = offchannel,
+ };
+
+ if (!phy->num_sta)
+ return;
+
+ local_bh_disable();
+ ieee80211_iterate_active_interfaces_atomic(phy->hw,
+ IEEE80211_IFACE_ITER_NORMAL,
+ mt76_offchannel_notify_iter, &data);
+ local_bh_enable();
+}
+EXPORT_SYMBOL_GPL(mt76_offchannel_notify);
+
+struct mt76_rx_beacon_data {
+ struct mt76_phy *phy;
+ const u8 *bssid;
+};
+
+static void mt76_rx_beacon_iter(void *_data, u8 *mac,
+ struct ieee80211_vif *vif)
+{
+ struct mt76_rx_beacon_data *data = _data;
+ struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv;
+ struct mt76_vif_data *mvif = mlink->mvif;
+ int link_id;
+
+ if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc)
+ return;
+
+ for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
+ struct ieee80211_bss_conf *link_conf;
+
+ if (link_id == mvif->deflink_id)
+ mlink = (struct mt76_vif_link *)vif->drv_priv;
+ else
+ mlink = rcu_dereference(mvif->link[link_id]);
+ if (!mlink || !mlink->beacon_mon_interval)
+ continue;
+
+ if (mt76_vif_link_phy(mlink) != data->phy)
+ continue;
+
+ link_conf = rcu_dereference(vif->link_conf[link_id]);
+ if (!link_conf)
+ continue;
+
+ if (!ether_addr_equal(link_conf->bssid, data->bssid) &&
+ (!link_conf->nontransmitted ||
+ !ether_addr_equal(link_conf->transmitter_bssid,
+ data->bssid)))
+ continue;
+
+ WRITE_ONCE(mlink->beacon_mon_last, jiffies);
+ }
+}
+
+void mt76_rx_beacon(struct mt76_phy *phy, struct sk_buff *skb)
+{
+ struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
+ struct ieee80211_hdr *hdr = mt76_skb_get_hdr(skb);
+ struct mt76_rx_beacon_data data = {
+ .phy = phy,
+ .bssid = hdr->addr3,
+ };
+
+ mt76_scan_rx_beacon(phy->dev, phy->chandef.chan);
+
+ if (!phy->num_sta)
+ return;
+
+ if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_ONLY_MONITOR))
+ return;
+
+ ieee80211_iterate_active_interfaces_atomic(phy->hw,
+ IEEE80211_IFACE_ITER_RESUME_ALL,
+ mt76_rx_beacon_iter, &data);
+}
+EXPORT_SYMBOL_GPL(mt76_rx_beacon);
+
+static void mt76_beacon_mon_iter(void *data, u8 *mac,
+ struct ieee80211_vif *vif)
+{
+ struct mt76_phy *phy = data;
+ struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv;
+ struct mt76_vif_data *mvif = mlink->mvif;
+ int link_id;
+
+ if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc)
+ return;
+
+ for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
+ if (link_id == mvif->deflink_id)
+ mlink = (struct mt76_vif_link *)vif->drv_priv;
+ else
+ mlink = rcu_dereference(mvif->link[link_id]);
+ if (!mlink || !mlink->beacon_mon_interval)
+ continue;
+
+ if (mt76_vif_link_phy(mlink) != phy)
+ continue;
+
+ if (time_after(jiffies,
+ READ_ONCE(mlink->beacon_mon_last) +
+ MT76_BEACON_MON_MAX_MISS * mlink->beacon_mon_interval))
+ ieee80211_beacon_loss(vif);
+ }
+}
+
+void mt76_beacon_mon_check(struct mt76_phy *phy)
+{
+ if (phy->offchannel)
+ return;
+
+ ieee80211_iterate_active_interfaces_atomic(phy->hw,
+ IEEE80211_IFACE_ITER_RESUME_ALL,
+ mt76_beacon_mon_iter, phy);
+}
+EXPORT_SYMBOL_GPL(mt76_beacon_mon_check);