From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH 12/24] wifi: mt76: add multi-radio remain_on_channel functions
Date: Thu, 2 Jan 2025 17:34:56 +0100 [thread overview]
Message-ID: <20250102163508.52945-12-nbd@nbd.name> (raw)
In-Reply-To: <20250102163508.52945-1-nbd@nbd.name>
This allows a driver using the generic channel context functions to
temporarily switch to another channel for off-channel rx/tx.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
drivers/net/wireless/mediatek/mt76/channel.c | 96 +++++++++++++++++++
drivers/net/wireless/mediatek/mt76/mac80211.c | 3 +
drivers/net/wireless/mediatek/mt76/mt76.h | 12 +++
drivers/net/wireless/mediatek/mt76/scan.c | 2 +-
4 files changed, 112 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/mediatek/mt76/channel.c b/drivers/net/wireless/mediatek/mt76/channel.c
index 541b32cb1f65..455c30700475 100644
--- a/drivers/net/wireless/mediatek/mt76/channel.c
+++ b/drivers/net/wireless/mediatek/mt76/channel.c
@@ -280,3 +280,99 @@ void mt76_put_vif_phy_link(struct mt76_phy *phy, struct ieee80211_vif *vif,
dev->drv->vif_link_remove(phy, vif, &vif->bss_conf, mlink);
kfree(mlink);
}
+
+static void mt76_roc_complete(struct mt76_phy *phy)
+{
+ struct mt76_vif_link *mlink = phy->roc_link;
+
+ if (!phy->roc_vif)
+ return;
+
+ if (mlink)
+ mlink->mvif->roc_phy = NULL;
+ if (phy->main_chandef.chan)
+ mt76_set_channel(phy, &phy->main_chandef, false);
+ mt76_put_vif_phy_link(phy, phy->roc_vif, phy->roc_link);
+ phy->roc_vif = NULL;
+ phy->roc_link = NULL;
+ ieee80211_remain_on_channel_expired(phy->hw);
+}
+
+void mt76_roc_complete_work(struct work_struct *work)
+{
+ struct mt76_phy *phy = container_of(work, struct mt76_phy, roc_work.work);
+ struct mt76_dev *dev = phy->dev;
+
+ mutex_lock(&dev->mutex);
+ mt76_roc_complete(phy);
+ mutex_unlock(&dev->mutex);
+}
+
+void mt76_abort_roc(struct mt76_phy *phy)
+{
+ struct mt76_dev *dev = phy->dev;
+
+ cancel_delayed_work_sync(&phy->roc_work);
+
+ mutex_lock(&dev->mutex);
+ mt76_roc_complete(phy);
+ mutex_unlock(&dev->mutex);
+}
+
+int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct ieee80211_channel *chan, int duration,
+ enum ieee80211_roc_type type)
+{
+ struct cfg80211_chan_def chandef = {};
+ struct mt76_phy *phy = hw->priv;
+ struct mt76_dev *dev = phy->dev;
+ struct mt76_vif_link *mlink;
+ int ret = 0;
+
+ phy = dev->band_phys[chan->band];
+ if (!phy)
+ return -EINVAL;
+
+ mutex_lock(&dev->mutex);
+
+ if (phy->roc_vif || dev->scan.phy == phy) {
+ ret = -EBUSY;
+ goto out;
+ }
+
+ mlink = mt76_get_vif_phy_link(phy, vif);
+ if (IS_ERR(mlink)) {
+ ret = PTR_ERR(mlink);
+ goto out;
+ }
+
+ mlink->mvif->roc_phy = phy;
+ phy->roc_vif = vif;
+ phy->roc_link = mlink;
+ cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_HT20);
+ mt76_set_channel(phy, &chandef, true);
+ ieee80211_ready_on_channel(hw);
+ ieee80211_queue_delayed_work(phy->hw, &phy->roc_work,
+ msecs_to_jiffies(duration));
+
+out:
+ mutex_unlock(&dev->mutex);
+ return ret;
+}
+EXPORT_SYMBOL_GPL(mt76_remain_on_channel);
+
+int mt76_cancel_remain_on_channel(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif)
+{
+ struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv;
+ struct mt76_vif_data *mvif = mlink->mvif;
+ struct mt76_phy *phy = mvif->roc_phy;
+
+ if (!phy)
+ return 0;
+
+ mt76_abort_roc(phy);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(mt76_cancel_remain_on_channel);
diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c
index 1d5abe40b0c3..cea5c70cfc23 100644
--- a/drivers/net/wireless/mediatek/mt76/mac80211.c
+++ b/drivers/net/wireless/mediatek/mt76/mac80211.c
@@ -431,6 +431,7 @@ mt76_phy_init(struct mt76_phy *phy, struct ieee80211_hw *hw)
INIT_LIST_HEAD(&phy->tx_list);
spin_lock_init(&phy->tx_lock);
+ INIT_DELAYED_WORK(&phy->roc_work, mt76_roc_complete_work);
if ((void *)phy != hw->priv)
return 0;
@@ -1998,5 +1999,7 @@ void mt76_vif_cleanup(struct mt76_dev *dev, struct ieee80211_vif *vif)
rcu_assign_pointer(mvif->link[0], NULL);
mt76_abort_scan(dev);
+ if (mvif->roc_phy)
+ mt76_abort_roc(mvif->roc_phy);
}
EXPORT_SYMBOL_GPL(mt76_vif_cleanup);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index b61f1eb138e8..132148f7b107 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -787,6 +787,7 @@ struct mt76_vif_link {
struct mt76_vif_data {
struct mt76_vif_link __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS];
+ struct mt76_phy *roc_phy;
u16 valid_links;
u8 deflink_id;
};
@@ -809,6 +810,10 @@ struct mt76_phy {
bool offchannel;
bool radar_enabled;
+ struct delayed_work roc_work;
+ struct ieee80211_vif *roc_vif;
+ struct mt76_vif_link *roc_link;
+
struct mt76_chanctx *chanctx;
struct mt76_channel_state *chan_state;
@@ -1521,6 +1526,11 @@ int mt76_switch_vif_chanctx(struct ieee80211_hw *hw,
struct ieee80211_vif_chanctx_switch *vifs,
int n_vifs,
enum ieee80211_chanctx_switch_mode mode);
+int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct ieee80211_channel *chan, int duration,
+ enum ieee80211_roc_type type);
+int mt76_cancel_remain_on_channel(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif);
int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
void *data, int len);
int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb,
@@ -1572,6 +1582,8 @@ int mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef,
bool offchannel);
void mt76_scan_work(struct work_struct *work);
void mt76_abort_scan(struct mt76_dev *dev);
+void mt76_roc_complete_work(struct work_struct *work);
+void mt76_abort_roc(struct mt76_phy *phy);
struct mt76_vif_link *mt76_get_vif_phy_link(struct mt76_phy *phy,
struct ieee80211_vif *vif);
void mt76_put_vif_phy_link(struct mt76_phy *phy, struct ieee80211_vif *vif,
diff --git a/drivers/net/wireless/mediatek/mt76/scan.c b/drivers/net/wireless/mediatek/mt76/scan.c
index 9f3485be5747..1c4f9deaaada 100644
--- a/drivers/net/wireless/mediatek/mt76/scan.c
+++ b/drivers/net/wireless/mediatek/mt76/scan.c
@@ -134,7 +134,7 @@ int mt76_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
mutex_lock(&dev->mutex);
- if (dev->scan.req) {
+ if (dev->scan.req || phy->roc_vif) {
ret = -EBUSY;
goto out;
}
--
2.47.1
next prev parent reply other threads:[~2025-01-02 16:35 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-02 16:34 [PATCH 01/24] wifi: mt76: add code for emulating hardware scanning Felix Fietkau
2025-01-02 16:34 ` [PATCH 02/24] wifi: mt76: add support for allocating a phy without hw Felix Fietkau
2025-01-02 16:34 ` [PATCH 03/24] wifi: mt76: rename struct mt76_vif to mt76_vif_link Felix Fietkau
2025-01-02 16:34 ` [PATCH 04/24] wifi: mt76: add vif link specific data structure Felix Fietkau
2025-01-02 16:34 ` [PATCH 05/24] wifi: mt76: mt7996: split link specific data from struct mt7996_vif Felix Fietkau
2025-01-02 16:34 ` [PATCH 06/24] wifi: mt76: initialize more wcid fields mt76_wcid_init Felix Fietkau
2025-01-02 16:34 ` [PATCH 07/24] wifi: mt76: add chanctx functions for multi-channel phy support Felix Fietkau
2025-01-02 16:34 ` [PATCH 08/24] wifi: mt76: remove dev->wcid_phy_mask Felix Fietkau
2025-01-02 16:34 ` [PATCH 09/24] wifi: mt76: add multi-radio support to a few core hw ops Felix Fietkau
2025-01-02 16:34 ` [PATCH 10/24] wifi: mt76: add multi-radio support to tx scheduling Felix Fietkau
2025-01-02 16:34 ` [PATCH 11/24] wifi: mt76: add multi-radio support to scanning code Felix Fietkau
2025-01-02 16:34 ` Felix Fietkau [this message]
2025-01-02 16:34 ` [PATCH 13/24] wifi: mt76: mt7996: use emulated hardware scan support Felix Fietkau
2025-01-02 16:34 ` [PATCH 14/24] wifi: mt76: mt7996: pass wcid to mt7996_mcu_sta_hdr_trans_tlv Felix Fietkau
2025-01-02 16:34 ` [PATCH 15/24] wifi: mt76: mt7996: prepare mt7996_mcu_add_dev/bss_info for MLO support Felix Fietkau
2025-01-02 16:35 ` [PATCH 16/24] wifi: mt76: mt7996: prepare mt7996_mcu_add_beacon " Felix Fietkau
2025-01-02 16:35 ` [PATCH 17/24] wifi: mt76: mt7996: prepare mt7996_mcu_set_tx " Felix Fietkau
2025-01-02 16:35 ` [PATCH 18/24] wifi: mt76: mt7996: prepare mt7996_mcu_set_timing " Felix Fietkau
2025-01-02 16:35 ` [PATCH 19/24] wifi: mt76: connac: prepare mt76_connac_mcu_sta_basic_tlv " Felix Fietkau
2025-01-02 16:35 ` [PATCH 20/24] wifi: mt76: mt7996: prepare mt7996_mcu_update_bss_color " Felix Fietkau
2025-01-02 16:35 ` [PATCH 21/24] wifi: mt76: connac: rework connac helpers Felix Fietkau
2025-01-02 16:35 ` [PATCH 22/24] wifi: mt76: mt7996: move all debugfs files to the primary phy Felix Fietkau
2025-01-02 16:35 ` [PATCH 23/24] wifi: mt76: mt7996: switch to single multi-radio wiphy Felix Fietkau
2025-05-01 21:45 ` Ben Greear
2025-01-02 16:35 ` [PATCH 24/24] wifi: mt76: mt7996: fix monitor mode Felix Fietkau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250102163508.52945-12-nbd@nbd.name \
--to=nbd@nbd.name \
--cc=linux-wireless@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox