1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Wed, 12 Aug 2020 17:04:22 +0200
3 Subject: [PATCH] mac80211: use rate provided via status->rate on
4 ieee80211_tx_status_ext for AQL
6 Since ieee80211_tx_info does not have enough room to encode HE rates, HE
7 drivers use status->rate to provide rate info.
8 Store it in struct sta_info and use it for AQL.
10 Signed-off-by: Felix Fietkau <nbd@nbd.name>
13 --- a/net/mac80211/airtime.c
14 +++ b/net/mac80211/airtime.c
15 @@ -487,14 +487,61 @@ u32 ieee80211_calc_rx_airtime(struct iee
17 EXPORT_SYMBOL_GPL(ieee80211_calc_rx_airtime);
19 +static bool ieee80211_fill_rate_info(struct ieee80211_hw *hw,
20 + struct ieee80211_rx_status *stat, u8 band,
21 + struct rate_info *ri)
23 + struct ieee80211_supported_band *sband = hw->wiphy->bands[band];
30 + stat->nss = ri->nss;
31 + stat->rate_idx = ri->mcs;
33 + if (ri->flags & RATE_INFO_FLAGS_HE_MCS)
34 + stat->encoding = RX_ENC_HE;
35 + else if (ri->flags & RATE_INFO_FLAGS_VHT_MCS)
36 + stat->encoding = RX_ENC_VHT;
37 + else if (ri->flags & RATE_INFO_FLAGS_MCS)
38 + stat->encoding = RX_ENC_HT;
40 + stat->encoding = RX_ENC_LEGACY;
42 + if (ri->flags & RATE_INFO_FLAGS_SHORT_GI)
43 + stat->enc_flags |= RX_ENC_FLAG_SHORT_GI;
45 + stat->he_gi = ri->he_gi;
47 + if (stat->encoding != RX_ENC_LEGACY)
51 + for (i = 0; i < sband->n_bitrates; i++) {
52 + if (ri->legacy != sband->bitrates[i].bitrate)
62 static u32 ieee80211_calc_tx_airtime_rate(struct ieee80211_hw *hw,
63 struct ieee80211_tx_rate *rate,
64 + struct rate_info *ri,
67 struct ieee80211_rx_status stat = {
71 + if (ieee80211_fill_rate_info(hw, &stat, band, ri))
74 if (rate->idx < 0 || !rate->count)
77 @@ -522,6 +569,7 @@ static u32 ieee80211_calc_tx_airtime_rat
78 stat.encoding = RX_ENC_LEGACY;
82 return ieee80211_calc_rx_airtime(hw, &stat, len);
85 @@ -536,7 +584,7 @@ u32 ieee80211_calc_tx_airtime(struct iee
86 struct ieee80211_tx_rate *rate = &info->status.rates[i];
89 - cur_duration = ieee80211_calc_tx_airtime_rate(hw, rate,
90 + cur_duration = ieee80211_calc_tx_airtime_rate(hw, rate, NULL,
94 @@ -573,6 +621,7 @@ u32 ieee80211_calc_expected_tx_airtime(s
95 struct sta_info *sta = container_of(pubsta, struct sta_info,
97 struct ieee80211_tx_rate *rate = &sta->tx_stats.last_rate;
98 + struct rate_info *ri = &sta->tx_stats.last_rate_info;
101 if (!(rate->flags & (IEEE80211_TX_RC_VHT_MCS |
102 @@ -586,7 +635,7 @@ u32 ieee80211_calc_expected_tx_airtime(s
103 * This will not be very accurate, but much better than simply
104 * assuming un-aggregated tx.
106 - airtime = ieee80211_calc_tx_airtime_rate(hw, rate, band,
107 + airtime = ieee80211_calc_tx_airtime_rate(hw, rate, ri, band,
108 ampdu ? len * 16 : len);
111 --- a/net/mac80211/sta_info.h
112 +++ b/net/mac80211/sta_info.h
113 @@ -609,6 +609,7 @@ struct sta_info {
114 u64 packets[IEEE80211_NUM_ACS];
115 u64 bytes[IEEE80211_NUM_ACS];
116 struct ieee80211_tx_rate last_rate;
117 + struct rate_info last_rate_info;
118 u64 msdu[IEEE80211_NUM_TIDS + 1];
120 u16 tid_seq[IEEE80211_QOS_CTL_TID_MASK + 1];
121 --- a/net/mac80211/status.c
122 +++ b/net/mac80211/status.c
123 @@ -1147,9 +1147,17 @@ void ieee80211_tx_status_ext(struct ieee
124 struct ieee80211_tx_info *info = status->info;
125 struct ieee80211_sta *pubsta = status->sta;
126 struct ieee80211_supported_band *sband;
127 + struct sta_info *sta;
129 bool acked, noack_success;
132 + sta = container_of(pubsta, struct sta_info, sta);
135 + sta->tx_stats.last_rate_info = *status->rate;
139 return __ieee80211_tx_status(hw, status);
141 @@ -1164,10 +1172,6 @@ void ieee80211_tx_status_ext(struct ieee
142 noack_success = !!(info->flags & IEEE80211_TX_STAT_NOACK_TRANSMITTED);
145 - struct sta_info *sta;
147 - sta = container_of(pubsta, struct sta_info, sta);
149 if (!acked && !noack_success)
150 sta->status_stats.retry_failed++;
151 sta->status_stats.retry_count += retry_count;