From: Miri Korenblit <miriam.rachel.korenblit@intel.com>
To: linux-wireless@vger.kernel.org
Subject: [PATCH v2 wireless-next 04/15] wifi: mac80211: run NAN DE code only when appropriate
Date: Thu, 26 Mar 2026 12:14:34 +0200 [thread overview]
Message-ID: <20260326121156.6665f64865cd.Iee24bef3bae2e1d502216192e760c1e699d271c9@changeid> (raw)
In-Reply-To: <20260326101445.1443198-1-miriam.rachel.korenblit@intel.com>
NAN DE (Discovery Engine) may be handled in the device or in user space.
When handled in user space, all the NAN func management code should not
run. Moreover, devices with user space DE should not provide the
add/del_nan_func callbaks. For such devices, ieee80211_reconfig_nan will
always fail.
Make it clear what parts of ieee80211_if_nan are relevant to DE
management, and touch those only when DE is offloaded.
Add a check that makes sure that a driver doesn't register with
add_del/nan_func callbacks if DE is in user space.
Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
---
net/mac80211/cfg.c | 52 ++++++++++++++++++++++++--------------
net/mac80211/ieee80211_i.h | 13 ++++++----
net/mac80211/iface.c | 25 +++++++++++-------
net/mac80211/main.c | 4 ++-
net/mac80211/util.c | 10 +++++---
5 files changed, 67 insertions(+), 37 deletions(-)
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 13132215afb4..e851668f4ef3 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -502,12 +502,15 @@ static int ieee80211_add_nan_func(struct wiphy *wiphy,
if (!ieee80211_sdata_running(sdata))
return -ENETDOWN;
- spin_lock_bh(&sdata->u.nan.func_lock);
+ if (WARN_ON(wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_USERSPACE_DE))
+ return -EOPNOTSUPP;
+
+ spin_lock_bh(&sdata->u.nan.de.func_lock);
- ret = idr_alloc(&sdata->u.nan.function_inst_ids,
+ ret = idr_alloc(&sdata->u.nan.de.function_inst_ids,
nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
GFP_ATOMIC);
- spin_unlock_bh(&sdata->u.nan.func_lock);
+ spin_unlock_bh(&sdata->u.nan.de.func_lock);
if (ret < 0)
return ret;
@@ -518,10 +521,10 @@ static int ieee80211_add_nan_func(struct wiphy *wiphy,
ret = drv_add_nan_func(sdata->local, sdata, nan_func);
if (ret) {
- spin_lock_bh(&sdata->u.nan.func_lock);
- idr_remove(&sdata->u.nan.function_inst_ids,
+ spin_lock_bh(&sdata->u.nan.de.func_lock);
+ idr_remove(&sdata->u.nan.de.function_inst_ids,
nan_func->instance_id);
- spin_unlock_bh(&sdata->u.nan.func_lock);
+ spin_unlock_bh(&sdata->u.nan.de.func_lock);
}
return ret;
@@ -534,9 +537,9 @@ ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
struct cfg80211_nan_func *func;
int id;
- lockdep_assert_held(&sdata->u.nan.func_lock);
+ lockdep_assert_held(&sdata->u.nan.de.func_lock);
- idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
+ idr_for_each_entry(&sdata->u.nan.de.function_inst_ids, func, id) {
if (func->cookie == cookie)
return func;
}
@@ -555,13 +558,16 @@ static void ieee80211_del_nan_func(struct wiphy *wiphy,
!ieee80211_sdata_running(sdata))
return;
- spin_lock_bh(&sdata->u.nan.func_lock);
+ if (WARN_ON(wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_USERSPACE_DE))
+ return;
+
+ spin_lock_bh(&sdata->u.nan.de.func_lock);
func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
if (func)
instance_id = func->instance_id;
- spin_unlock_bh(&sdata->u.nan.func_lock);
+ spin_unlock_bh(&sdata->u.nan.de.func_lock);
if (instance_id)
drv_del_nan_func(sdata->local, sdata, instance_id);
@@ -4888,18 +4894,22 @@ void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
return;
- spin_lock_bh(&sdata->u.nan.func_lock);
+ if (WARN_ON(sdata->local->hw.wiphy->nan_capa.flags &
+ WIPHY_NAN_FLAGS_USERSPACE_DE))
+ return;
+
+ spin_lock_bh(&sdata->u.nan.de.func_lock);
- func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
+ func = idr_find(&sdata->u.nan.de.function_inst_ids, inst_id);
if (WARN_ON(!func)) {
- spin_unlock_bh(&sdata->u.nan.func_lock);
+ spin_unlock_bh(&sdata->u.nan.de.func_lock);
return;
}
cookie = func->cookie;
- idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
+ idr_remove(&sdata->u.nan.de.function_inst_ids, inst_id);
- spin_unlock_bh(&sdata->u.nan.func_lock);
+ spin_unlock_bh(&sdata->u.nan.de.func_lock);
cfg80211_free_nan_func(func);
@@ -4918,16 +4928,20 @@ void ieee80211_nan_func_match(struct ieee80211_vif *vif,
if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
return;
- spin_lock_bh(&sdata->u.nan.func_lock);
+ if (WARN_ON(sdata->local->hw.wiphy->nan_capa.flags &
+ WIPHY_NAN_FLAGS_USERSPACE_DE))
+ return;
+
+ spin_lock_bh(&sdata->u.nan.de.func_lock);
- func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
+ func = idr_find(&sdata->u.nan.de.function_inst_ids, match->inst_id);
if (WARN_ON(!func)) {
- spin_unlock_bh(&sdata->u.nan.func_lock);
+ spin_unlock_bh(&sdata->u.nan.de.func_lock);
return;
}
match->cookie = func->cookie;
- spin_unlock_bh(&sdata->u.nan.func_lock);
+ spin_unlock_bh(&sdata->u.nan.de.func_lock);
cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
}
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 53d783769642..8d5f9a725fdf 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -987,16 +987,19 @@ struct ieee80211_if_mntr {
*
* @conf: current NAN configuration
* @started: true iff NAN is started
- * @func_lock: lock for @func_inst_ids
- * @function_inst_ids: a bitmap of available instance_id's
+ * @de: Discovery Engine state (only valid if !WIPHY_NAN_FLAGS_USERSPACE_DE)
+ * @de.func_lock: lock for @de.function_inst_ids
+ * @de.function_inst_ids: a bitmap of available instance_id's
*/
struct ieee80211_if_nan {
struct cfg80211_nan_conf conf;
bool started;
- /* protects function_inst_ids */
- spinlock_t func_lock;
- struct idr function_inst_ids;
+ struct {
+ /* protects function_inst_ids */
+ spinlock_t func_lock;
+ struct idr function_inst_ids;
+ } de;
};
struct ieee80211_link_data_managed {
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 7518dcbcdf1c..f0a5a675c5a5 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -622,15 +622,19 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata, bool going_do
break;
case NL80211_IFTYPE_NAN:
/* clean all the functions */
- spin_lock_bh(&sdata->u.nan.func_lock);
+ if (!(local->hw.wiphy->nan_capa.flags &
+ WIPHY_NAN_FLAGS_USERSPACE_DE)) {
+ spin_lock_bh(&sdata->u.nan.de.func_lock);
+
+ idr_for_each_entry(&sdata->u.nan.de.function_inst_ids,
+ func, i) {
+ idr_remove(&sdata->u.nan.de.function_inst_ids, i);
+ cfg80211_free_nan_func(func);
+ }
+ idr_destroy(&sdata->u.nan.de.function_inst_ids);
- idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, i) {
- idr_remove(&sdata->u.nan.function_inst_ids, i);
- cfg80211_free_nan_func(func);
+ spin_unlock_bh(&sdata->u.nan.de.func_lock);
}
- idr_destroy(&sdata->u.nan.function_inst_ids);
-
- spin_unlock_bh(&sdata->u.nan.func_lock);
break;
default:
wiphy_work_cancel(sdata->local->hw.wiphy, &sdata->work);
@@ -1942,8 +1946,11 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
MONITOR_FLAG_OTHER_BSS;
break;
case NL80211_IFTYPE_NAN:
- idr_init(&sdata->u.nan.function_inst_ids);
- spin_lock_init(&sdata->u.nan.func_lock);
+ if (!(sdata->local->hw.wiphy->nan_capa.flags &
+ WIPHY_NAN_FLAGS_USERSPACE_DE)) {
+ idr_init(&sdata->u.nan.de.function_inst_ids);
+ spin_lock_init(&sdata->u.nan.de.func_lock);
+ }
sdata->vif.bss_conf.bssid = sdata->vif.addr;
break;
case NL80211_IFTYPE_AP_VLAN:
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index d1bb6353908d..f47dd58770ad 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -1157,7 +1157,9 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
if (WARN_ON(local->hw.wiphy->interface_modes &
BIT(NL80211_IFTYPE_NAN) &&
- (!local->ops->start_nan || !local->ops->stop_nan)))
+ ((!local->ops->start_nan || !local->ops->stop_nan) ||
+ (local->hw.wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_USERSPACE_DE &&
+ (local->ops->add_nan_func || local->ops->del_nan_func)))))
return -EINVAL;
if (hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO) {
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 38b0c42c4c13..36795529ff82 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -1754,6 +1754,10 @@ static int ieee80211_reconfig_nan(struct ieee80211_sub_if_data *sdata)
if (WARN_ON(res))
return res;
+ if (sdata->local->hw.wiphy->nan_capa.flags &
+ WIPHY_NAN_FLAGS_USERSPACE_DE)
+ return 0;
+
funcs = kzalloc_objs(*funcs, sdata->local->hw.max_nan_de_entries + 1);
if (!funcs)
return -ENOMEM;
@@ -1762,12 +1766,12 @@ static int ieee80211_reconfig_nan(struct ieee80211_sub_if_data *sdata)
* This is a little bit ugly. We need to call a potentially sleeping
* callback for each NAN function, so we can't hold the spinlock.
*/
- spin_lock_bh(&sdata->u.nan.func_lock);
+ spin_lock_bh(&sdata->u.nan.de.func_lock);
- idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id)
+ idr_for_each_entry(&sdata->u.nan.de.function_inst_ids, func, id)
funcs[i++] = func;
- spin_unlock_bh(&sdata->u.nan.func_lock);
+ spin_unlock_bh(&sdata->u.nan.de.func_lock);
for (i = 0; funcs[i]; i++) {
res = drv_add_nan_func(sdata->local, sdata, funcs[i]);
--
2.34.1
next prev parent reply other threads:[~2026-03-26 10:15 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 10:14 [PATCH v2 wireless-next 00/15] wifi: mac80211: add NAN support Miri Korenblit
2026-03-26 10:14 ` [PATCH v2 wireless-next 01/15] wifi: mac80211: add a TXQ for management frames on NAN devices Miri Korenblit
2026-03-26 10:14 ` [PATCH v2 wireless-next 02/15] wifi: ieee80211: add more NAN definitions Miri Korenblit
2026-03-26 10:14 ` [PATCH v2 wireless-next 03/15] wifi: mac80211: export ieee80211_calculate_rx_timestamp Miri Korenblit
2026-03-26 10:14 ` Miri Korenblit [this message]
2026-03-26 10:14 ` [PATCH v2 wireless-next 05/15] wifi: mac80211: add NAN local schedule support Miri Korenblit
2026-03-26 10:14 ` [PATCH v2 wireless-next 06/15] wifi: mac80211: support open and close for NAN_DATA interfaces Miri Korenblit
2026-03-26 10:14 ` [PATCH v2 wireless-next 07/15] wifi: mac80211: handle reconfig for NAN DATA interfaces Miri Korenblit
2026-03-26 10:14 ` [PATCH v2 wireless-next 08/15] wifi: mac80211: support NAN stations Miri Korenblit
2026-03-26 10:14 ` [PATCH v2 wireless-next 09/15] wifi: mac80211: add NAN peer schedule support Miri Korenblit
2026-03-26 10:14 ` [PATCH v2 wireless-next 10/15] wifi: mac80211: update NAN data path state on schedule changes Miri Korenblit
2026-03-26 10:14 ` [PATCH v2 wireless-next 11/15] wifi: mac80211: add support for TX over NAN_DATA interfaces Miri Korenblit
2026-03-26 10:14 ` [PATCH v2 wireless-next 12/15] wifi: mac80211: Accept frames on NAN DATA interfaces Miri Korenblit
2026-03-26 10:14 ` [PATCH v2 wireless-next 13/15] wifi: mac80211: allow block ack agreements in NAN Data Miri Korenblit
2026-03-26 10:14 ` [PATCH v2 wireless-next 14/15] wifi: mac80211: report and drop spurious NAN Data frames Miri Korenblit
2026-03-26 10:14 ` [PATCH v2 wireless-next 15/15] wifi: mac80211: allow add_key on NAN interfaces Miri Korenblit
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=20260326121156.6665f64865cd.Iee24bef3bae2e1d502216192e760c1e699d271c9@changeid \
--to=miriam.rachel.korenblit@intel.com \
--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