From: Johannes Berg Qualcomm reported that there can be a lot of lock contention on the wiphy mutex due to background processes dumping the station statistics. In many drivers (e.g. all mac80211 drivers without their own station statistics) it doesn't need to be locked, the data is never guaranteed to be fully consistent anyway given it's collected by concurrent TX/RX. Support unlocked get/dump station methods so that drivers can reduce lock contention by implementing these methods. As in the other cases, it's allowed to return -EAGAIN if a locked call is needed. Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 14 +++ net/wireless/nl80211.c | 201 ++++++++++++++++++++++++++++++++-------- net/wireless/rdev-ops.h | 27 ++++++ net/wireless/trace.h | 19 +++- 4 files changed, 219 insertions(+), 42 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index d7fe077a8748..7e34382e78ae 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4963,7 +4963,13 @@ struct mgmt_frame_regs { * them, also against the existing state! Drivers must call * cfg80211_check_station_change() to validate the information. * @get_station: get station information for the station identified by @mac + * @get_station_unlocked: Like @get_station, but called without the wiphy + * mutex. Return -EAGAIN to get @get_station called with the wiphy mutex + * held instead. * @dump_station: dump station callback -- resume dump at index @idx + * @dump_station_unlocked: Like @dump_station, but called without the wiphy + * mutex. Return -EAGAIN to get @dump_station called with the wiphy mutex + * held instead. * * @add_mpath: add a fixed mesh path * @del_mpath: delete a given mesh path @@ -5395,8 +5401,16 @@ struct cfg80211_ops { struct station_parameters *params); int (*get_station)(struct wiphy *wiphy, struct wireless_dev *wdev, const u8 *mac, struct station_info *sinfo); + int (*get_station_unlocked)(struct wiphy *wiphy, + struct wireless_dev *wdev, + const u8 *mac, + struct station_info *sinfo); int (*dump_station)(struct wiphy *wiphy, struct wireless_dev *wdev, int idx, u8 *mac, struct station_info *sinfo); + int (*dump_station_unlocked)(struct wiphy *wiphy, + struct wireless_dev *wdev, + int idx, u8 *mac, + struct station_info *sinfo); int (*add_mpath)(struct wiphy *wiphy, struct net_device *dev, const u8 *dst, const u8 *next_hop); diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index b8adb25e8dc3..8d8003716476 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -266,23 +266,51 @@ nl80211_lock_and_recheck(struct cfg80211_registered_device *rdev, return ERR_PTR(-ENODEV); } +/* like nl80211_lock_and_recheck() but under RCU, for wdev_hold() */ +static struct wireless_dev * +nl80211_wdev_by_id_rcu(struct cfg80211_registered_device *rdev, + struct net *netns, u32 wdev_id) +{ + struct wireless_dev *wdev; + + if (!net_eq(wiphy_net(&rdev->wiphy), netns)) + return NULL; + + list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { + if (wdev->identifier != wdev_id) + continue; + if (wdev->netdev && !net_eq(dev_net(wdev->netdev), netns)) + return NULL; + return wdev; + } + + return NULL; +} + /* * Must have wdev_hold(), acquire the wiphy mutex. This has to * look up the wdev again (otherwise it could deadlock against * wdev removal), so it can return an error pointer. */ static struct wireless_dev * -nl80211_lock_held_wdev(struct cfg80211_registered_device *rdev, - struct genl_info *info, struct wireless_dev *wdev) +__nl80211_lock_held_wdev(struct cfg80211_registered_device *rdev, + struct net *netns, struct wireless_dev *wdev) { u32 wdev_id = wdev->identifier; /* the wdev reference was keeping the wiphy alive */ get_device(&rdev->wiphy.dev); - info->user_ptr[1] = NULL; wdev_put(wdev); - wdev = nl80211_lock_and_recheck(rdev, genl_info_net(info), wdev_id); + return nl80211_lock_and_recheck(rdev, netns, wdev_id); +} + +static struct wireless_dev * +nl80211_lock_held_wdev(struct cfg80211_registered_device *rdev, + struct genl_info *info, struct wireless_dev *wdev) +{ + info->user_ptr[1] = NULL; + wdev = __nl80211_lock_held_wdev(rdev, genl_info_net(info), wdev); if (IS_ERR(wdev)) return wdev; @@ -1326,10 +1354,10 @@ nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, }; -static int nl80211_prepare_wdev_dump(struct netlink_callback *cb, - struct cfg80211_registered_device **rdev, - struct wireless_dev **wdev, - struct nlattr **attrbuf) +static int __nl80211_prepare_wdev_dump(struct netlink_callback *cb, + struct cfg80211_registered_device **rdev, + struct wireless_dev **wdev, + struct nlattr **attrbuf, bool lock) { struct net *netns = sock_net(cb->skb->sk); u32 wdev_id; @@ -1374,13 +1402,22 @@ static int nl80211_prepare_wdev_dump(struct netlink_callback *cb, wdev_id = cb->args[1]; } - get_device(&(*rdev)->wiphy.dev); - rcu_read_unlock(); + if (!lock) { + *wdev = nl80211_wdev_by_id_rcu(*rdev, netns, wdev_id); + if (*wdev) + wdev_hold(*wdev); + rcu_read_unlock(); + if (!*wdev) + return -ENODEV; + } else { + get_device(&(*rdev)->wiphy.dev); + rcu_read_unlock(); - /* things may have changed since the lookup or the last dumpit call */ - *wdev = nl80211_lock_and_recheck(*rdev, netns, wdev_id); - if (IS_ERR(*wdev)) - return PTR_ERR(*wdev); + /* things may have changed since the lookup or last dumpit */ + *wdev = nl80211_lock_and_recheck(*rdev, netns, wdev_id); + if (IS_ERR(*wdev)) + return PTR_ERR(*wdev); + } /* 0 is the first index - add 1 to parse only once */ cb->args[0] = (*rdev)->wiphy_idx + 1; @@ -1389,6 +1426,14 @@ static int nl80211_prepare_wdev_dump(struct netlink_callback *cb, return 0; } +static int nl80211_prepare_wdev_dump(struct netlink_callback *cb, + struct cfg80211_registered_device **rdev, + struct wireless_dev **wdev, + struct nlattr **attrbuf) +{ + return __nl80211_prepare_wdev_dump(cb, rdev, wdev, attrbuf, true); +} + /* message building helper */ void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, int flags, u8 cmd) @@ -8836,13 +8881,46 @@ static int nl80211_put_link_station_payload(struct sk_buff *msg, return -EMSGSIZE; } +static int nl80211_fill_station_info(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + struct nl80211_dump_station_ctx *ctx, + bool locked) +{ + int err; + + if (!ctx->filter_mac) { + if (locked) + return rdev_dump_station(rdev, wdev, ctx->sta_idx, + ctx->mac_addr, &ctx->sinfo); + if (!rdev->ops->dump_station_unlocked) + return -EAGAIN; + return rdev_dump_station_unlocked(rdev, wdev, ctx->sta_idx, + ctx->mac_addr, &ctx->sinfo); + } + + if (locked) + err = rdev_get_station(rdev, wdev, ctx->filter_mac_addr, + &ctx->sinfo); + else if (rdev->ops->get_station_unlocked) + err = rdev_get_station_unlocked(rdev, wdev, ctx->filter_mac_addr, + &ctx->sinfo); + else + return -EAGAIN; + + if (!err) + memcpy(ctx->mac_addr, ctx->filter_mac_addr, ETH_ALEN); + return err; +} + static int nl80211_dump_station(struct sk_buff *skb, struct netlink_callback *cb) { struct cfg80211_registered_device *rdev; struct wireless_dev *wdev; struct nl80211_dump_station_ctx *ctx = (void *)cb->args[2]; + struct net *netns = sock_net(cb->skb->sk); struct nlattr **attrbuf __free(kfree) = NULL; + bool locked = false; int err; if (!ctx) { @@ -8851,11 +8929,9 @@ static int nl80211_dump_station(struct sk_buff *skb, return -ENOMEM; } - err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, attrbuf); + err = __nl80211_prepare_wdev_dump(cb, &rdev, &wdev, attrbuf, false); if (err) return err; - /* nl80211_prepare_wdev_dump acquired it in the successful case */ - __acquire(&rdev->wiphy.mtx); if (!ctx) { ctx = kzalloc_obj(*ctx); @@ -8912,21 +8988,28 @@ static int nl80211_dump_station(struct sk_buff *skb, } } - if (ctx->filter_mac) { - if (ctx->sta_idx > 0) { - err = skb->len; - goto out_err_release; + if (ctx->filter_mac && ctx->sta_idx > 0) { + err = skb->len; + goto out_err_release; + } + + err = nl80211_fill_station_info(rdev, wdev, ctx, + locked); + if (err == -EAGAIN && !locked) { + cfg80211_sinfo_release_content(&ctx->sinfo); + memset(&ctx->sinfo, 0, sizeof(ctx->sinfo)); + + /* this fails if the wdev is being removed */ + wdev = __nl80211_lock_held_wdev(rdev, netns, + wdev); + if (IS_ERR(wdev)) { + err = PTR_ERR(wdev); + goto out_err; } - err = rdev_get_station(rdev, wdev, - ctx->filter_mac_addr, - &ctx->sinfo); - if (!err) - memcpy(ctx->mac_addr, - ctx->filter_mac_addr, ETH_ALEN); - } else { - err = rdev_dump_station(rdev, wdev, ctx->sta_idx, - ctx->mac_addr, - &ctx->sinfo); + + /* try again locked now */ + locked = true; + continue; } if (err == -ENOENT) { err = skb->len; @@ -9021,7 +9104,10 @@ static int nl80211_dump_station(struct sk_buff *skb, cfg80211_sinfo_release_content(&ctx->sinfo); memset(&ctx->sinfo, 0, sizeof(ctx->sinfo)); out_err: - wiphy_unlock(&rdev->wiphy); + if (locked) + wiphy_unlock(&rdev->wiphy); + else if (wdev) + wdev_put(wdev); return err; } @@ -9042,6 +9128,7 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) struct cfg80211_registered_device *rdev = info->user_ptr[0]; struct wireless_dev *wdev = info->user_ptr[1]; struct station_info sinfo; + bool locked = false; struct sk_buff *msg; u8 *mac_addr = NULL; int err, i; @@ -9067,26 +9154,54 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) } } - err = rdev_get_station(rdev, wdev, mac_addr, &sinfo); - if (err) { - cfg80211_sinfo_release_content(&sinfo); - return err; - } - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) { cfg80211_sinfo_release_content(&sinfo); return -ENOMEM; } + err = -EAGAIN; + if (rdev->ops->get_station_unlocked) { + err = rdev_get_station_unlocked(rdev, wdev, mac_addr, &sinfo); + + if (err == -EAGAIN) { + cfg80211_sinfo_release_content(&sinfo); + memset(&sinfo, 0, sizeof(sinfo)); + } + } + + if (err == -EAGAIN) { + /* the wdev pointer is only valid until unlocking after this */ + info->user_ptr[1] = NULL; + /* can fail if the wdev is being removed */ + wdev = __nl80211_lock_held_wdev(rdev, genl_info_net(info), + wdev); + if (IS_ERR(wdev)) { + err = PTR_ERR(wdev); + } else { + locked = true; + err = rdev_get_station(rdev, wdev, mac_addr, &sinfo); + } + } + + if (err) { + cfg80211_sinfo_release_content(&sinfo); + goto out; + } + if (sinfo.valid_links) cfg80211_sta_set_mld_sinfo(&sinfo); if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, info->snd_portid, info->snd_seq, 0, - rdev, wdev, mac_addr, &sinfo) < 0) { + rdev, wdev, mac_addr, &sinfo) < 0) + err = -ENOBUFS; +out: + if (locked) + wiphy_unlock(&rdev->wiphy); + if (err) { nlmsg_free(msg); - return -ENOBUFS; + return err; } return genlmsg_reply(msg, info); @@ -19887,6 +20002,9 @@ nl80211_epcs_cfg(struct sk_buff *skb, struct genl_info *info) NL80211_FLAG_NEED_WIPHY) \ SELECTOR(__sel, WDEV, \ NL80211_FLAG_NEED_WDEV) \ + SELECTOR(__sel, WDEV_NOMTX, \ + NL80211_FLAG_NEED_WDEV | \ + NL80211_FLAG_NO_WIPHY_MTX) \ SELECTOR(__sel, NETDEV, \ NL80211_FLAG_NEED_NETDEV) \ SELECTOR(__sel, NETDEV_LINK, \ @@ -20316,7 +20434,8 @@ static const struct genl_ops nl80211_ops[] = { .doit = nl80211_get_station, .dumpit = nl80211_dump_station, .done = nl80211_dump_station_done, - .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV), + .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV | + NL80211_FLAG_NO_WIPHY_MTX), }, }; diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h index 5502cd947844..ae15cec9bf8b 100644 --- a/net/wireless/rdev-ops.h +++ b/net/wireless/rdev-ops.h @@ -248,6 +248,19 @@ static inline int rdev_get_station(struct cfg80211_registered_device *rdev, return ret; } +static inline int +rdev_get_station_unlocked(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, const u8 *mac, + struct station_info *sinfo) +{ + int ret; + + trace_rdev_get_station_unlocked(&rdev->wiphy, wdev, mac); + ret = rdev->ops->get_station_unlocked(&rdev->wiphy, wdev, mac, sinfo); + trace_rdev_return_int_station_info(&rdev->wiphy, ret, sinfo); + return ret; +} + static inline int rdev_dump_station(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev, int idx, u8 *mac, struct station_info *sinfo) @@ -259,6 +272,20 @@ static inline int rdev_dump_station(struct cfg80211_registered_device *rdev, return ret; } +static inline int +rdev_dump_station_unlocked(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, int idx, u8 *mac, + struct station_info *sinfo) +{ + int ret; + + trace_rdev_dump_station_unlocked(&rdev->wiphy, wdev, idx, mac); + ret = rdev->ops->dump_station_unlocked(&rdev->wiphy, wdev, idx, mac, + sinfo); + trace_rdev_return_int_station_info(&rdev->wiphy, ret, sinfo); + return ret; +} + static inline int rdev_add_mpath(struct cfg80211_registered_device *rdev, struct net_device *dev, u8 *dst, u8 *next_hop) { diff --git a/net/wireless/trace.h b/net/wireless/trace.h index 1f3c1e0eb26a..31000ffebe43 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -1056,12 +1056,17 @@ DEFINE_EVENT(wiphy_wdev_mac_evt, rdev_get_station, TP_ARGS(wiphy, wdev, mac) ); +DEFINE_EVENT(wiphy_wdev_mac_evt, rdev_get_station_unlocked, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, const u8 *mac), + TP_ARGS(wiphy, wdev, mac) +); + DEFINE_EVENT(wiphy_netdev_mac_evt, rdev_del_mpath, TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, const u8 *mac), TP_ARGS(wiphy, netdev, mac) ); -TRACE_EVENT(rdev_dump_station, +DECLARE_EVENT_CLASS(rdev_dump_station_evt, TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, int _idx, u8 *mac), TP_ARGS(wiphy, wdev, _idx, mac), @@ -1082,6 +1087,18 @@ TRACE_EVENT(rdev_dump_station, __entry->idx) ); +DEFINE_EVENT(rdev_dump_station_evt, rdev_dump_station, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, int _idx, + u8 *mac), + TP_ARGS(wiphy, wdev, _idx, mac) +); + +DEFINE_EVENT(rdev_dump_station_evt, rdev_dump_station_unlocked, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, int _idx, + u8 *mac), + TP_ARGS(wiphy, wdev, _idx, mac) +); + TRACE_EVENT(rdev_return_int_station_info, TP_PROTO(struct wiphy *wiphy, int ret, struct station_info *sinfo), TP_ARGS(wiphy, ret, sinfo), -- 2.56.0 From: Johannes Berg Refactor the code a bit to pass around link-STA pointers instead of looking them up again and again. This will simplify the next changes, since otherwise all of these lookups would have to be converted to RCU-safe ones. It also simplifies the code generally. Signed-off-by: Johannes Berg --- net/mac80211/sta_info.c | 87 ++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c index 9252aaa39895..d761847b70b3 100644 --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c @@ -2547,20 +2547,11 @@ void ieee80211_sta_update_pending_airtime(struct ieee80211_local *local, } static struct ieee80211_sta_rx_stats * -sta_get_last_rx_stats(struct sta_info *sta, int link_id) +sta_get_last_rx_stats(struct link_sta_info *link_sta_info) { - struct ieee80211_sta_rx_stats *stats; - struct link_sta_info *link_sta_info; + struct ieee80211_sta_rx_stats *stats = &link_sta_info->rx_stats; int cpu; - if (link_id < 0) - link_sta_info = &sta->deflink; - else - link_sta_info = wiphy_dereference(sta->local->hw.wiphy, - sta->link[link_id]); - - stats = &link_sta_info->rx_stats; - if (!link_sta_info->pcpu_rx_stats) return stats; @@ -2576,6 +2567,19 @@ sta_get_last_rx_stats(struct sta_info *sta, int link_id) return stats; } +static unsigned long sta_link_last_active(struct link_sta_info *link_sta_info) +{ + struct ieee80211_sta_rx_stats *stats; + + stats = sta_get_last_rx_stats(link_sta_info); + + if (!link_sta_info->status_stats.last_ack || + time_after(stats->last_rx, link_sta_info->status_stats.last_ack)) + return stats->last_rx; + + return link_sta_info->status_stats.last_ack; +} + static void sta_stats_decode_rate(struct ieee80211_local *local, u32 rate, struct rate_info *rinfo) { @@ -2653,10 +2657,11 @@ static void sta_stats_decode_rate(struct ieee80211_local *local, u32 rate, } } -static int sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo, - int link_id) +static int sta_set_rate_info_rx(struct sta_info *sta, + struct link_sta_info *link_sta_info, + struct rate_info *rinfo) { - u32 rate = READ_ONCE(sta_get_last_rx_stats(sta, link_id)->last_rate); + u32 rate = READ_ONCE(sta_get_last_rx_stats(link_sta_info)->last_rate); if (rate == STA_STATS_RATE_INVALID) return -EINVAL; @@ -2680,19 +2685,13 @@ static inline u64 sta_get_tidstats_msdu(struct ieee80211_sta_rx_stats *rxstats, } static void sta_set_tidstats(struct sta_info *sta, + struct link_sta_info *link_sta_info, struct cfg80211_tid_stats *tidstats, - int tid, int link_id) + int tid, bool txq_stats) { struct ieee80211_local *local = sta->local; - struct link_sta_info *link_sta_info; int cpu; - if (link_id < 0) - link_sta_info = &sta->deflink; - else - link_sta_info = wiphy_dereference(sta->local->hw.wiphy, - sta->link[link_id]); - if (!(tidstats->filled & BIT(NL80211_TID_STATS_RX_MSDU))) { tidstats->rx_msdu += sta_get_tidstats_msdu(&link_sta_info->rx_stats, @@ -2731,7 +2730,7 @@ static void sta_set_tidstats(struct sta_info *sta, link_sta_info->status_stats.msdu_failed[tid]; } - if (link_id < 0 && tid < IEEE80211_NUM_TIDS) { + if (txq_stats && tid < IEEE80211_NUM_TIDS) { spin_lock_bh(&local->fq.lock); tidstats->filled |= BIT(NL80211_TID_STATS_TXQ_STATS); @@ -2837,20 +2836,17 @@ static u32 sta_estimate_expected_throughput(struct sta_info *sta, } static void sta_set_link_sinfo(struct sta_info *sta, + struct link_sta_info *link_sta_info, struct link_station_info *link_sinfo, struct ieee80211_link_data *link, bool tidstats) { struct ieee80211_sub_if_data *sdata = sta->sdata; struct ieee80211_sta_rx_stats *last_rxstats; - int i, ac, cpu, link_id = link->link_id; - struct link_sta_info *link_sta_info; + int i, ac, cpu; u32 thr = 0; - last_rxstats = sta_get_last_rx_stats(sta, link_id); - - link_sta_info = wiphy_dereference(sta->local->hw.wiphy, - sta->link[link_id]); + last_rxstats = sta_get_last_rx_stats(link_sta_info); /* do before driver, so beacon filtering drivers have a * chance to e.g. just add the number of filtered beacons @@ -2876,8 +2872,7 @@ static void sta_set_link_sinfo(struct sta_info *sta, link_sinfo->inactive_time = jiffies_delta_to_msecs(jiffies - - ieee80211_sta_last_active(sta, - link_id)); + sta_link_last_active(link_sta_info)); if (!(link_sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES64) | BIT_ULL(NL80211_STA_INFO_TX_BYTES)))) { @@ -3025,8 +3020,8 @@ static void sta_set_link_sinfo(struct sta_info *sta, } if (!(link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE))) { - if (sta_set_rate_info_rx(sta, &link_sinfo->rxrate, - link_id) == 0) + if (sta_set_rate_info_rx(sta, link_sta_info, + &link_sinfo->rxrate) == 0) link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE); } @@ -3034,8 +3029,8 @@ static void sta_set_link_sinfo(struct sta_info *sta, if (tidstats && !cfg80211_link_sinfo_alloc_tid_stats(link_sinfo, GFP_KERNEL)) { for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) - sta_set_tidstats(sta, &link_sinfo->pertid[i], i, - link_id); + sta_set_tidstats(sta, link_sta_info, + &link_sinfo->pertid[i], i, false); } if (sdata->vif.type == NL80211_IFTYPE_STATION) { @@ -3091,7 +3086,7 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, int i, ac, cpu; struct ieee80211_sta_rx_stats *last_rxstats; - last_rxstats = sta_get_last_rx_stats(sta, -1); + last_rxstats = sta_get_last_rx_stats(&sta->deflink); sinfo->generation = sdata->local->sta_generation; @@ -3119,7 +3114,7 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, sinfo->assoc_at = sta->assoc_at; sinfo->inactive_time = jiffies_delta_to_msecs(jiffies - - ieee80211_sta_last_active(sta, -1)); + sta_link_last_active(&sta->deflink)); if (!(sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES64) | BIT_ULL(NL80211_STA_INFO_TX_BYTES)))) { @@ -3258,13 +3253,15 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) && !sta->sta.valid_links) { - if (sta_set_rate_info_rx(sta, &sinfo->rxrate, -1) == 0) + if (sta_set_rate_info_rx(sta, &sta->deflink, + &sinfo->rxrate) == 0) sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE); } if (tidstats && !cfg80211_sinfo_alloc_tid_stats(sinfo, GFP_KERNEL)) { for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) - sta_set_tidstats(sta, &sinfo->pertid[i], i, -1); + sta_set_tidstats(sta, &sta->deflink, + &sinfo->pertid[i], i, true); } #ifdef CONFIG_MAC80211_MESH @@ -3367,7 +3364,8 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, sinfo->valid_links &= ~BIT(link_id); continue; } - sta_set_link_sinfo(sta, link_sinfo, link, tidstats); + sta_set_link_sinfo(sta, link_sta, link_sinfo, link, + tidstats); if (!thr && (link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_EXPECTED_THROUGHPUT))) est_thr += link_sinfo->expected_throughput; @@ -3400,22 +3398,15 @@ u32 sta_get_expected_throughput(struct sta_info *sta) unsigned long ieee80211_sta_last_active(struct sta_info *sta, int link_id) { - struct ieee80211_sta_rx_stats *stats; struct link_sta_info *link_sta_info; - stats = sta_get_last_rx_stats(sta, link_id); - if (link_id < 0) link_sta_info = &sta->deflink; else link_sta_info = wiphy_dereference(sta->local->hw.wiphy, sta->link[link_id]); - if (!link_sta_info->status_stats.last_ack || - time_after(stats->last_rx, link_sta_info->status_stats.last_ack)) - return stats->last_rx; - - return link_sta_info->status_stats.last_ack; + return sta_link_last_active(link_sta_info); } int ieee80211_sta_allocate_link(struct sta_info *sta, unsigned int link_id) -- 2.56.0 From: Johannes Berg Implement the new cfg80211 unlocked STA statistics. If the driver has an operation, then we need to always do the locked again, so return -EAGAIN unconditionally if it has a locked but not atomic operation, but drivers can implement the new atomic methods to provide needed data atomically (and can also return -EAGAIN). This should, given a driver without any ops or adding the atomic ops, reduce wiphy mutex contention. Signed-off-by: Johannes Berg --- include/net/mac80211.h | 18 ++++++ net/mac80211/cfg.c | 120 ++++++++++++++++++++++++++++---------- net/mac80211/driver-ops.c | 76 ++++++++++++++++++++++++ net/mac80211/driver-ops.h | 46 ++++----------- net/mac80211/sta_info.c | 54 ++++++++++------- net/mac80211/sta_info.h | 10 +++- 6 files changed, 233 insertions(+), 91 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index 2a61079e3975..a1a6409b44c1 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -4369,6 +4369,13 @@ struct ieee80211_prep_tx_info { * Statistics that the driver doesn't fill will be filled by mac80211. * The callback can sleep. * + * @sta_statistics_atomic: Like @sta_statistics, but called under RCU, so it + * must be atomic. This is called instead of @sta_statistics if available, + * but may return -EAGAIN to fall back to @sta_statistics with the wiphy + * mutex held. + * Note that it's not guaranteed this will always be called first, some + * (internal) calls may call @sta_statistics directly. + * * @link_sta_statistics: Get link statistics for this station. For example with * beacon filtering, the statistics kept by mac80211 might not be * accurate, so let the driver pre-fill the statistics. The driver can @@ -4378,6 +4385,9 @@ struct ieee80211_prep_tx_info { * Statistics that the driver doesn't fill will be filled by mac80211. * The callback can sleep. * + * @link_sta_statistics_atomic: Like @link_sta_statistics, with the same + * locking/retry semantics as @sta_statistics_atomic. Must be atomic. + * * @conf_tx: Configure TX queue parameters (EDCF (aifs, cw_min, cw_max), * bursting) for a hardware TX queue. * Returns a negative error code on failure. @@ -4883,6 +4893,10 @@ struct ieee80211_ops { struct ieee80211_vif *vif, struct ieee80211_sta *sta, struct station_info *sinfo); + int (*sta_statistics_atomic)(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_sta *sta, + struct station_info *sinfo); int (*conf_tx)(struct ieee80211_hw *hw, struct ieee80211_vif *vif, unsigned int link_id, u16 ac, @@ -4898,6 +4912,10 @@ struct ieee80211_ops { struct ieee80211_vif *vif, struct ieee80211_link_sta *link_sta, struct link_station_info *link_sinfo); + int (*link_sta_statistics_atomic)(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_link_sta *link_sta, + struct link_station_info *link_sinfo); /** * @ampdu_action: diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index c2af0599e59c..9ca40c20f185 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -1018,31 +1018,63 @@ void sta_set_rate_info_tx(struct sta_info *sta, rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI; } +static int __ieee80211_dump_station(struct ieee80211_sub_if_data *sdata, + int idx, u8 *mac, + struct station_info *sinfo, bool locked) +{ + struct sta_info *sta; + int ret; + + sta = sta_info_get_by_idx(sdata, idx); + if (!sta) + return -ENOENT; + + memcpy(mac, sta->sta.addr, ETH_ALEN); + ret = __sta_set_sinfo(sta, sinfo, true, locked); + if (ret) + return ret; + + /* + * Add accumulated removed link data to sinfo data for + * consistency for MLO + */ + if (sinfo->valid_links) + sta_set_accumulated_removed_links_sinfo(sta, sinfo); + + return 0; +} + static int ieee80211_dump_station(struct wiphy *wiphy, struct wireless_dev *wdev, int idx, u8 *mac, struct station_info *sinfo) { struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); - struct ieee80211_local *local = sdata->local; - struct sta_info *sta; - int ret = -ENOENT; - lockdep_assert_wiphy(local->hw.wiphy); + lockdep_assert_wiphy(sdata->local->hw.wiphy); - sta = sta_info_get_by_idx(sdata, idx); - if (sta) { - ret = 0; - memcpy(mac, sta->sta.addr, ETH_ALEN); - sta_set_sinfo(sta, sinfo, true); + return __ieee80211_dump_station(sdata, idx, mac, sinfo, true); +} - /* Add accumulated removed link data to sinfo data for - * consistency for MLO - */ - if (sinfo->valid_links) - sta_set_accumulated_removed_links_sinfo(sta, sinfo); +/* driver must have atomic ops (or none), otherwise we need the mutex */ +static bool ieee80211_sta_stats_need_mtx(struct ieee80211_local *local) +{ + const struct ieee80211_ops *ops = local->ops; - } + return (ops->sta_statistics && !ops->sta_statistics_atomic) || + (ops->link_sta_statistics && !ops->link_sta_statistics_atomic); +} - return ret; +static int ieee80211_dump_station_unlocked(struct wiphy *wiphy, + struct wireless_dev *wdev, + int idx, u8 *mac, + struct station_info *sinfo) +{ + struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); + + if (ieee80211_sta_stats_need_mtx(sdata->local)) + return -EAGAIN; + + guard(rcu)(); + return __ieee80211_dump_station(sdata, idx, mac, sinfo, false); } static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev, @@ -1053,30 +1085,54 @@ static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev, return drv_get_survey(local, idx, survey); } +static int __ieee80211_get_station(struct ieee80211_sub_if_data *sdata, + const u8 *mac, struct station_info *sinfo, + bool locked) +{ + struct sta_info *sta; + int ret; + + sta = sta_info_get_bss(sdata, mac); + if (!sta) + return -ENOENT; + + ret = __sta_set_sinfo(sta, sinfo, true, locked); + if (ret) + return ret; + + /* + * Add accumulated removed link data to sinfo data for + * consistency for MLO + */ + if (sinfo->valid_links) + sta_set_accumulated_removed_links_sinfo(sta, sinfo); + + return 0; +} + static int ieee80211_get_station(struct wiphy *wiphy, struct wireless_dev *wdev, const u8 *mac, struct station_info *sinfo) { struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); - struct ieee80211_local *local = sdata->local; - struct sta_info *sta; - int ret = -ENOENT; - lockdep_assert_wiphy(local->hw.wiphy); + lockdep_assert_wiphy(sdata->local->hw.wiphy); - sta = sta_info_get_bss(sdata, mac); - if (sta) { - ret = 0; - sta_set_sinfo(sta, sinfo, true); + return __ieee80211_get_station(sdata, mac, sinfo, true); +} - /* Add accumulated removed link data to sinfo data for - * consistency for MLO - */ - if (sinfo->valid_links) - sta_set_accumulated_removed_links_sinfo(sta, sinfo); - } +static int ieee80211_get_station_unlocked(struct wiphy *wiphy, + struct wireless_dev *wdev, + const u8 *mac, + struct station_info *sinfo) +{ + struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); - return ret; + if (ieee80211_sta_stats_need_mtx(sdata->local)) + return -EAGAIN; + + guard(rcu)(); + return __ieee80211_get_station(sdata, mac, sinfo, false); } static int ieee80211_set_monitor_channel(struct wiphy *wiphy, @@ -6255,7 +6311,9 @@ const struct cfg80211_ops mac80211_config_ops = { .del_station = ieee80211_del_station, .change_station = ieee80211_change_station, .get_station = ieee80211_get_station, + .get_station_unlocked = ieee80211_get_station_unlocked, .dump_station = ieee80211_dump_station, + .dump_station_unlocked = ieee80211_dump_station_unlocked, .dump_survey = ieee80211_dump_survey, #ifdef CONFIG_MAC80211_MESH .add_mpath = ieee80211_add_mpath, diff --git a/net/mac80211/driver-ops.c b/net/mac80211/driver-ops.c index 49753b73aba2..ffdaf9143b9b 100644 --- a/net/mac80211/driver-ops.c +++ b/net/mac80211/driver-ops.c @@ -633,3 +633,79 @@ int drv_change_sta_links(struct ieee80211_local *local, return 0; } + +int drv_sta_statistics(struct ieee80211_local *local, + struct ieee80211_sub_if_data *sdata, + struct ieee80211_sta *sta, + struct station_info *sinfo, + bool locked) +{ + int ret; + + sdata = get_bss_sdata(sdata); + if (!check_sdata_in_driver(sdata)) + return 0; + + trace_drv_sta_statistics(local, sdata, sta); + + if (!locked) { + might_sleep(); + lockdep_assert_wiphy(local->hw.wiphy); + + ret = 0; + + if (local->ops->sta_statistics) + local->ops->sta_statistics(&local->hw, + &sdata->vif, + sta, sinfo); + } else { + ret = -EAGAIN; + + if (local->ops->sta_statistics_atomic) + ret = local->ops->sta_statistics_atomic(&local->hw, + &sdata->vif, + sta, sinfo); + } + + trace_drv_return_int(local, ret); + + return ret; +} + +int drv_link_sta_statistics(struct ieee80211_local *local, + struct ieee80211_sub_if_data *sdata, + struct ieee80211_link_sta *link_sta, + struct link_station_info *link_sinfo, + bool locked) +{ + int ret; + + sdata = get_bss_sdata(sdata); + if (!check_sdata_in_driver(sdata)) + return 0; + + if (locked) { + might_sleep(); + lockdep_assert_wiphy(local->hw.wiphy); + + ret = 0; + + if (local->ops->link_sta_statistics) + local->ops->link_sta_statistics(&local->hw, + &sdata->vif, + link_sta, + link_sinfo); + } else { + ret = -EAGAIN; + + if (local->ops->sta_statistics_atomic) + ret = local->ops->link_sta_statistics_atomic(&local->hw, + &sdata->vif, + link_sta, + link_sinfo); + } + + trace_drv_return_int(local, ret); + + return 0; +} diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h index accd89bbc1fb..83dd15f2daf6 100644 --- a/net/mac80211/driver-ops.h +++ b/net/mac80211/driver-ops.h @@ -617,42 +617,16 @@ static inline void drv_sta_rate_tbl_update(struct ieee80211_local *local, trace_drv_return_void(local); } -static inline void drv_sta_statistics(struct ieee80211_local *local, - struct ieee80211_sub_if_data *sdata, - struct ieee80211_sta *sta, - struct station_info *sinfo) -{ - might_sleep(); - lockdep_assert_wiphy(local->hw.wiphy); - - sdata = get_bss_sdata(sdata); - if (!check_sdata_in_driver(sdata)) - return; - - trace_drv_sta_statistics(local, sdata, sta); - if (local->ops->sta_statistics) - local->ops->sta_statistics(&local->hw, &sdata->vif, sta, sinfo); - trace_drv_return_void(local); -} - -static inline void drv_link_sta_statistics(struct ieee80211_local *local, - struct ieee80211_sub_if_data *sdata, - struct ieee80211_link_sta *link_sta, - struct link_station_info *link_sinfo) -{ - might_sleep(); - lockdep_assert_wiphy(local->hw.wiphy); - - sdata = get_bss_sdata(sdata); - if (!check_sdata_in_driver(sdata)) - return; - - trace_drv_link_sta_statistics(local, sdata, link_sta); - if (local->ops->link_sta_statistics) - local->ops->link_sta_statistics(&local->hw, &sdata->vif, - link_sta, link_sinfo); - trace_drv_return_void(local); -} +int drv_sta_statistics(struct ieee80211_local *local, + struct ieee80211_sub_if_data *sdata, + struct ieee80211_sta *sta, + struct station_info *sinfo, + bool locked); +int drv_link_sta_statistics(struct ieee80211_local *local, + struct ieee80211_sub_if_data *sdata, + struct ieee80211_link_sta *link_sta, + struct link_station_info *link_sinfo, + bool locked); int drv_conf_tx(struct ieee80211_local *local, struct ieee80211_link_data *link, u16 ac, diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c index d761847b70b3..5c95ffee257d 100644 --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c @@ -2822,7 +2822,7 @@ static u32 sta_estimate_expected_throughput(struct sta_info *sta, u32 duration; u8 band; - conf = sdata_dereference(bss_conf->chanctx_conf, sta->sdata); + conf = rcu_dereference_wiphy(hw->wiphy, bss_conf->chanctx_conf); if (!conf) return 0; band = conf->def.chan->band; @@ -2835,15 +2835,15 @@ static u32 sta_estimate_expected_throughput(struct sta_info *sta, return ((1024 * USEC_PER_SEC) / duration) * 8; } -static void sta_set_link_sinfo(struct sta_info *sta, - struct link_sta_info *link_sta_info, - struct link_station_info *link_sinfo, - struct ieee80211_link_data *link, - bool tidstats) +static int sta_set_link_sinfo(struct sta_info *sta, + struct link_sta_info *link_sta_info, + struct link_station_info *link_sinfo, + struct ieee80211_link_data *link, + bool tidstats, bool locked) { struct ieee80211_sub_if_data *sdata = sta->sdata; struct ieee80211_sta_rx_stats *last_rxstats; - int i, ac, cpu; + int i, ac, cpu, ret; u32 thr = 0; last_rxstats = sta_get_last_rx_stats(link_sta_info); @@ -2857,9 +2857,10 @@ static void sta_set_link_sinfo(struct sta_info *sta, ether_addr_copy(link_sinfo->addr, link_sta_info->addr); - drv_link_sta_statistics(sta->local, sdata, - link_sta_info->pub, - link_sinfo); + ret = drv_link_sta_statistics(sta->local, sdata, link_sta_info->pub, + link_sinfo, locked); + if (ret) + return ret; link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) | BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC); @@ -3027,7 +3028,7 @@ static void sta_set_link_sinfo(struct sta_info *sta, } if (tidstats && !cfg80211_link_sinfo_alloc_tid_stats(link_sinfo, - GFP_KERNEL)) { + GFP_ATOMIC)) { for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) sta_set_tidstats(sta, link_sta_info, &link_sinfo->pertid[i], i, false); @@ -3075,15 +3076,17 @@ static void sta_set_link_sinfo(struct sta_info *sta, link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG); } + + return 0; } -void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, - bool tidstats) +int __sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, + bool tidstats, bool locked) { struct ieee80211_sub_if_data *sdata = sta->sdata; struct ieee80211_local *local = sdata->local; u32 thr = 0; - int i, ac, cpu; + int i, ac, cpu, ret; struct ieee80211_sta_rx_stats *last_rxstats; last_rxstats = sta_get_last_rx_stats(&sta->deflink); @@ -3097,7 +3100,10 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, if (sdata->vif.type == NL80211_IFTYPE_STATION) sinfo->rx_beacon = sdata->deflink.u.mgd.count_beacon_signal; - drv_sta_statistics(local, sdata, &sta->sta, sinfo); + ret = drv_sta_statistics(local, sdata, &sta->sta, sinfo, locked); + if (ret) + return ret; + sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) | BIT_ULL(NL80211_STA_INFO_STA_FLAGS) | BIT_ULL(NL80211_STA_INFO_CONNECTED_TIME) | @@ -3258,7 +3264,7 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE); } - if (tidstats && !cfg80211_sinfo_alloc_tid_stats(sinfo, GFP_KERNEL)) { + if (tidstats && !cfg80211_sinfo_alloc_tid_stats(sinfo, GFP_ATOMIC)) { for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) sta_set_tidstats(sta, &sta->deflink, &sinfo->pertid[i], i, true); @@ -3355,17 +3361,19 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, for_each_valid_link(sinfo, link_id) { struct link_station_info *link_sinfo = sinfo->links[link_id]; - link_sta = wiphy_dereference(sta->local->hw.wiphy, - sta->link[link_id]); - link = wiphy_dereference(sdata->local->hw.wiphy, - sdata->link[link_id]); + link_sta = rcu_dereference_wiphy(sta->local->hw.wiphy, + sta->link[link_id]); + link = rcu_dereference_wiphy(sdata->local->hw.wiphy, + sdata->link[link_id]); if (!link_sta || !link_sinfo || !link) { sinfo->valid_links &= ~BIT(link_id); continue; } - sta_set_link_sinfo(sta, link_sta, link_sinfo, link, - tidstats); + ret = sta_set_link_sinfo(sta, link_sta, link_sinfo, link, + tidstats, locked); + if (ret) + return ret; if (!thr && (link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_EXPECTED_THROUGHPUT))) est_thr += link_sinfo->expected_throughput; @@ -3375,6 +3383,8 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, sinfo->expected_throughput = est_thr; } } + + return 0; } u32 sta_get_expected_throughput(struct sta_info *sta) diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h index f409f6a3afa1..8942541375b2 100644 --- a/net/mac80211/sta_info.h +++ b/net/mac80211/sta_info.h @@ -989,8 +989,14 @@ static inline int sta_info_flush(struct ieee80211_sub_if_data *sdata, void sta_set_rate_info_tx(struct sta_info *sta, const struct ieee80211_tx_rate *rate, struct rate_info *rinfo); -void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, - bool tidstats); +int __sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, + bool tidstats, bool locked); + +static inline void sta_set_sinfo(struct sta_info *sta, + struct station_info *sinfo, bool tidstats) +{ + __sta_set_sinfo(sta, sinfo, tidstats, true); +} void sta_set_accumulated_removed_links_sinfo(struct sta_info *sta, struct station_info *sinfo); -- 2.56.0 From: Johannes Berg Most of the time we just return cached statistics, that can be done unlocked. If querying the firmware is needed, return -EAGAIN to fall back to the locked version. Signed-off-by: Johannes Berg --- drivers/net/wireless/ath/ath12k/mac.c | 117 +++++++++++++++------ drivers/net/wireless/ath/ath12k/mac.h | 8 ++ drivers/net/wireless/ath/ath12k/wifi7/hw.c | 2 + 3 files changed, 94 insertions(+), 33 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c index 196b807210de..c8af44c333cb 100644 --- a/drivers/net/wireless/ath/ath12k/mac.c +++ b/drivers/net/wireless/ath/ath12k/mac.c @@ -920,7 +920,8 @@ struct ath12k *ath12k_get_ar_by_vif(struct ieee80211_hw *hw, struct ath12k_hw *ah = ath12k_hw_to_ah(hw); struct ath12k_link_vif *arvif; - lockdep_assert_wiphy(hw->wiphy); + /* also used under RCU for station statistics */ + lockdep_assert(lockdep_is_held(&hw->wiphy->mtx) || rcu_read_lock_held()); /* If there is one pdev within ah, then we return * ar directly. @@ -931,7 +932,7 @@ struct ath12k *ath12k_get_ar_by_vif(struct ieee80211_hw *hw, if (!(ahvif->links_map & BIT(link_id))) return NULL; - arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); + arvif = rcu_dereference_wiphy(hw->wiphy, ahvif->link[link_id]); if (arvif && arvif->is_created) return arvif->ar; @@ -13737,10 +13738,11 @@ static void ath12k_mac_put_chain_rssi(struct station_info *sinfo, } } -void ath12k_mac_op_sta_statistics(struct ieee80211_hw *hw, - struct ieee80211_vif *vif, - struct ieee80211_sta *sta, - struct station_info *sinfo) +static int ath12k_mac_sta_statistics(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_sta *sta, + struct station_info *sinfo, + bool atomic) { struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); struct ath12k_dp_link_peer_rate_info rate_info = {}; @@ -13752,12 +13754,17 @@ void ath12k_mac_op_sta_statistics(struct ieee80211_hw *hw, struct ath12k *ar; bool db2dbm; - lockdep_assert_wiphy(hw->wiphy); + /* station interfaces query the firmware, which sleeps */ + if (atomic && ahsta->ahvif->vdev_type == WMI_VDEV_TYPE_STA) + return -EAGAIN; + + if (!atomic) + lockdep_assert_wiphy(hw->wiphy); arsta = &ahsta->deflink; ar = ath12k_get_ar_by_vif(hw, vif, arsta->link_id); if (!ar) - return; + return 0; dp = ath12k_ab_to_dp(ar->ab); ath12k_dp_link_peer_get_sta_rate_info_stats(dp, arsta->addr, &rate_info); @@ -13791,23 +13798,22 @@ void ath12k_mac_op_sta_statistics(struct ieee80211_hw *hw, /* TODO: Use real NF instead of default one. */ signal = rate_info.rssi_comb; - params.pdev_id = ath12k_mac_get_target_pdev_id(ar); - params.vdev_id = 0; - params.stats_id = WMI_REQUEST_VDEV_STAT; + if (ahsta->ahvif->vdev_type == WMI_VDEV_TYPE_STA) { + params.pdev_id = ath12k_mac_get_target_pdev_id(ar); + params.vdev_id = 0; + params.stats_id = WMI_REQUEST_VDEV_STAT; - if (!signal && - ahsta->ahvif->vdev_type == WMI_VDEV_TYPE_STA && - !(ath12k_mac_get_fw_stats(ar, ¶ms))) { - signal = arsta->rssi_beacon; - ath12k_fw_stats_reset(ar); - } + if (!signal && !ath12k_mac_get_fw_stats(ar, ¶ms)) { + signal = arsta->rssi_beacon; + ath12k_fw_stats_reset(ar); + } - params.stats_id = WMI_REQUEST_RSSI_PER_CHAIN_STAT; - if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) && - ahsta->ahvif->vdev_type == WMI_VDEV_TYPE_STA && - !(ath12k_mac_get_fw_stats(ar, ¶ms))) { - ath12k_mac_put_chain_rssi(sinfo, arsta); - ath12k_fw_stats_reset(ar); + params.stats_id = WMI_REQUEST_RSSI_PER_CHAIN_STAT; + if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) && + !ath12k_mac_get_fw_stats(ar, ¶ms)) { + ath12k_mac_put_chain_rssi(sinfo, arsta); + ath12k_fw_stats_reset(ar); + } } spin_lock_bh(&ar->data_lock); @@ -13830,7 +13836,7 @@ void ath12k_mac_op_sta_statistics(struct ieee80211_hw *hw, peer = ath12k_dp_link_peer_find_by_addr(dp, arsta->addr); if (!peer) { spin_unlock_bh(&dp->dp_lock); - return; + return 0; } sinfo->tx_retries = peer->tx_retry_count; @@ -13839,13 +13845,32 @@ void ath12k_mac_op_sta_statistics(struct ieee80211_hw *hw, sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED); spin_unlock_bh(&dp->dp_lock); + return 0; +} + +void ath12k_mac_op_sta_statistics(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_sta *sta, + struct station_info *sinfo) +{ + ath12k_mac_sta_statistics(hw, vif, sta, sinfo, false); } EXPORT_SYMBOL(ath12k_mac_op_sta_statistics); -void ath12k_mac_op_link_sta_statistics(struct ieee80211_hw *hw, - struct ieee80211_vif *vif, - struct ieee80211_link_sta *link_sta, - struct link_station_info *link_sinfo) +int ath12k_mac_op_sta_statistics_atomic(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_sta *sta, + struct station_info *sinfo) +{ + return ath12k_mac_sta_statistics(hw, vif, sta, sinfo, true); +} +EXPORT_SYMBOL(ath12k_mac_op_sta_statistics_atomic); + +static int ath12k_mac_link_sta_statistics(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_link_sta *link_sta, + struct link_station_info *link_sinfo, + bool atomic) { struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(link_sta->sta); struct ath12k_fw_stats_req_params params = {}; @@ -13855,16 +13880,22 @@ void ath12k_mac_op_link_sta_statistics(struct ieee80211_hw *hw, s8 signal; bool db2dbm; - lockdep_assert_wiphy(hw->wiphy); + /* station interfaces query the firmware, which sleeps */ + if (atomic && ahsta->ahvif->vdev_type == WMI_VDEV_TYPE_STA) + return -EAGAIN; - arsta = wiphy_dereference(hw->wiphy, ahsta->link[link_sta->link_id]); + if (!atomic) + lockdep_assert_wiphy(hw->wiphy); + + arsta = rcu_dereference_wiphy(hw->wiphy, + ahsta->link[link_sta->link_id]); if (!arsta) - return; + return 0; ar = ath12k_get_ar_by_vif(hw, vif, arsta->link_id); if (!ar) - return; + return 0; db2dbm = test_bit(WMI_TLV_SERVICE_HW_DB2DBM_CONVERSION_SUPPORT, ar->ab->wmi_ab.svc_map); @@ -13873,7 +13904,7 @@ void ath12k_mac_op_link_sta_statistics(struct ieee80211_hw *hw, peer = ath12k_dp_link_peer_find_by_addr(ar->ab->dp, arsta->addr); if (!peer) { spin_unlock_bh(&ar->ab->dp->dp_lock); - return; + return 0; } link_sinfo->rx_duration = peer->rx_duration; @@ -13934,9 +13965,29 @@ void ath12k_mac_op_link_sta_statistics(struct ieee80211_hw *hw, db2dbm ? signal : signal + ATH12K_DEFAULT_NOISE_FLOOR; link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL); } + + return 0; +} + +void ath12k_mac_op_link_sta_statistics(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_link_sta *link_sta, + struct link_station_info *link_sinfo) +{ + ath12k_mac_link_sta_statistics(hw, vif, link_sta, link_sinfo, false); } EXPORT_SYMBOL(ath12k_mac_op_link_sta_statistics); +int ath12k_mac_op_link_sta_statistics_atomic(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_link_sta *link_sta, + struct link_station_info *link_sinfo) +{ + return ath12k_mac_link_sta_statistics(hw, vif, link_sta, link_sinfo, + true); +} +EXPORT_SYMBOL(ath12k_mac_op_link_sta_statistics_atomic); + int ath12k_mac_op_cancel_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif) { diff --git a/drivers/net/wireless/ath/ath12k/mac.h b/drivers/net/wireless/ath/ath12k/mac.h index aba98afd4365..530672fd8da7 100644 --- a/drivers/net/wireless/ath/ath12k/mac.h +++ b/drivers/net/wireless/ath/ath12k/mac.h @@ -311,10 +311,18 @@ void ath12k_mac_op_sta_statistics(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta, struct station_info *sinfo); +int ath12k_mac_op_sta_statistics_atomic(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_sta *sta, + struct station_info *sinfo); void ath12k_mac_op_link_sta_statistics(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_link_sta *link_sta, struct link_station_info *link_sinfo); +int ath12k_mac_op_link_sta_statistics_atomic(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_link_sta *link_sta, + struct link_station_info *link_sinfo); int ath12k_mac_op_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_channel *chan, diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hw.c b/drivers/net/wireless/ath/ath12k/wifi7/hw.c index aec7c652808c..8a721afa05a3 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hw.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hw.c @@ -1207,7 +1207,9 @@ static const struct ieee80211_ops ath12k_ops_wifi7 = { .get_survey = ath12k_mac_op_get_survey, .flush = ath12k_mac_op_flush, .sta_statistics = ath12k_mac_op_sta_statistics, + .sta_statistics_atomic = ath12k_mac_op_sta_statistics_atomic, .link_sta_statistics = ath12k_mac_op_link_sta_statistics, + .link_sta_statistics_atomic = ath12k_mac_op_link_sta_statistics_atomic, .remain_on_channel = ath12k_mac_op_remain_on_channel, .cancel_remain_on_channel = ath12k_mac_op_cancel_remain_on_channel, .change_sta_links = ath12k_mac_op_change_sta_links, -- 2.56.0