361-mac80211-estimate-expected-throughput-if-not-provide.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. From: Felix Fietkau <[email protected]>
  2. Date: Wed, 6 Aug 2025 10:52:03 +0200
  3. Subject: [PATCH] mac80211: estimate expected throughput if not provided by
  4. driver/rc
  5. Estimate the tx throughput based on the expected per-packet tx time.
  6. This is useful for mesh implementations that rely on expected throughput,
  7. e.g. 802.11s or batman-adv.
  8. Signed-off-by: Felix Fietkau <[email protected]>
  9. ---
  10. --- a/net/mac80211/sta_info.c
  11. +++ b/net/mac80211/sta_info.c
  12. @@ -2977,6 +2977,29 @@ static void sta_set_link_sinfo(struct st
  13. }
  14. }
  15. +static u32 sta_estimate_expected_throughput(struct sta_info *sta,
  16. + struct station_info *sinfo)
  17. +{
  18. + struct ieee80211_sub_if_data *sdata = sta->sdata;
  19. + struct ieee80211_local *local = sdata->local;
  20. + struct rate_info *ri = &sinfo->txrate;
  21. + struct ieee80211_hw *hw = &local->hw;
  22. + struct ieee80211_chanctx_conf *conf;
  23. + u32 duration;
  24. + u8 band = 0;
  25. +
  26. + conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
  27. + if (conf)
  28. + band = conf->def.chan->band;
  29. +
  30. + duration = ieee80211_rate_expected_tx_airtime(hw, NULL, ri, band, true, 1024);
  31. + duration += duration >> 4; /* add assumed packet error rate of ~6% */
  32. + if (!duration)
  33. + return 0;
  34. +
  35. + return ((1024 * USEC_PER_SEC) / duration) * 8;
  36. +}
  37. +
  38. void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo,
  39. bool tidstats)
  40. {
  41. @@ -3201,6 +3224,8 @@ void sta_set_sinfo(struct sta_info *sta,
  42. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
  43. thr = sta_get_expected_throughput(sta);
  44. + if (!thr && (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)))
  45. + thr = sta_estimate_expected_throughput(sta, sinfo);
  46. if (thr != 0) {
  47. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_EXPECTED_THROUGHPUT);