From: Toke Høiland-Jørgensen <toke@xxxxxxxxxx> To implement airtime queue limits, we need an estimate of the transmission rate a station is currently transmitting at. The ath10k driver already keeps this internally, so add an API function to pass this up to mac80211. We also keep a pre-calculated 64-bit reciprocal that will be used in the actual calculations, to avoid a division operation in the fast path. Signed-off-by: Toke Høiland-Jørgensen <toke@xxxxxxxxxx> --- include/net/mac80211.h | 10 ++++++++++ net/mac80211/ieee80211_i.h | 4 ++++ net/mac80211/sta_info.c | 9 +++++++++ net/mac80211/sta_info.h | 2 ++ 4 files changed, 25 insertions(+) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index b12d378621b0..1b7f4a370122 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -4529,6 +4529,16 @@ void ieee80211_get_tx_rates(struct ieee80211_vif *vif, void ieee80211_sta_set_expected_throughput(struct ieee80211_sta *pubsta, u32 thr); +/** + * ieee80211_sta_set_last_tx_bitrate - set last tx rate for station + * + * This sets the last TX bitrate for a given station. + * + * @sta: Pointer to the station + * @bitrate: Bitrate in kbps + */ +void ieee80211_sta_set_last_tx_bitrate(struct ieee80211_sta *sta, u32 bitrate); + /** * ieee80211_tx_rate_update - transmit rate update callback * diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 05406e9c05b3..9de5390411ba 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -59,6 +59,10 @@ struct ieee80211_local; /* power level hasn't been configured (or set to automatic) */ #define IEEE80211_UNSET_POWER_LEVEL INT_MIN +/* constants for calculating reciprocals to avoid division in fast path */ +#define IEEE80211_RECIPROCAL_DIVISOR 0x100000000ULL +#define IEEE80211_RECIPROCAL_SHIFT 32 + /* * Some APs experience problems when working with U-APSD. Decreasing the * probability of that happening by using legacy mode for all ACs but VO isn't diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c index df553070206c..aae878ffe94c 100644 --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c @@ -2481,3 +2481,12 @@ void ieee80211_sta_set_expected_throughput(struct ieee80211_sta *pubsta, sta_update_codel_params(sta, thr); } + +void ieee80211_sta_set_last_tx_bitrate(struct ieee80211_sta *pubsta, + u32 rate) +{ + struct sta_info *sta = container_of(pubsta, struct sta_info, sta); + + sta->last_tx_bitrate = rate; + sta->last_tx_bitrate_reciprocal = ((u64)IEEE80211_RECIPROCAL_DIVISOR / rate); +} diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h index 369c2dddce52..dd1a0b87f234 100644 --- a/net/mac80211/sta_info.h +++ b/net/mac80211/sta_info.h @@ -617,6 +617,8 @@ struct sta_info { const struct ieee80211_cipher_scheme *cipher_scheme; struct codel_params cparams; + u32 last_tx_bitrate; + u64 last_tx_bitrate_reciprocal; u8 reserved_tid;