06db852c30469fa8edfed0b0048b435cab4a4709
[openwrt/staging/dangole.git] /
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Wed, 12 Aug 2020 17:06:12 +0200
3 Subject: [PATCH] mac80211: factor out code to look up the average packet
4 length duration for a rate
5
6 This will be used to enhance AQL estimated aggregation length
7
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
9 ---
10
11 --- a/net/mac80211/airtime.c
12 +++ b/net/mac80211/airtime.c
13 @@ -405,18 +405,14 @@ ieee80211_calc_legacy_rate_duration(u16
14 return duration;
15 }
16
17 -u32 ieee80211_calc_rx_airtime(struct ieee80211_hw *hw,
18 - struct ieee80211_rx_status *status,
19 - int len)
20 +static u32 ieee80211_get_rate_duration(struct ieee80211_hw *hw,
21 + struct ieee80211_rx_status *status,
22 + u32 *overhead)
23 {
24 - struct ieee80211_supported_band *sband;
25 - const struct ieee80211_rate *rate;
26 bool sgi = status->enc_flags & RX_ENC_FLAG_SHORT_GI;
27 - bool sp = status->enc_flags & RX_ENC_FLAG_SHORTPRE;
28 int bw, streams;
29 int group, idx;
30 u32 duration;
31 - bool cck;
32
33 switch (status->bw) {
34 case RATE_INFO_BW_20:
35 @@ -437,20 +433,6 @@ u32 ieee80211_calc_rx_airtime(struct iee
36 }
37
38 switch (status->encoding) {
39 - case RX_ENC_LEGACY:
40 - if (WARN_ON_ONCE(status->band > NL80211_BAND_5GHZ))
41 - return 0;
42 -
43 - sband = hw->wiphy->bands[status->band];
44 - if (!sband || status->rate_idx >= sband->n_bitrates)
45 - return 0;
46 -
47 - rate = &sband->bitrates[status->rate_idx];
48 - cck = rate->flags & IEEE80211_RATE_MANDATORY_B;
49 -
50 - return ieee80211_calc_legacy_rate_duration(rate->bitrate, sp,
51 - cck, len);
52 -
53 case RX_ENC_VHT:
54 streams = status->nss;
55 idx = status->rate_idx;
56 @@ -477,13 +459,47 @@ u32 ieee80211_calc_rx_airtime(struct iee
57
58 duration = airtime_mcs_groups[group].duration[idx];
59 duration <<= airtime_mcs_groups[group].shift;
60 + *overhead = 36 + (streams << 2);
61 +
62 + return duration;
63 +}
64 +
65 +
66 +u32 ieee80211_calc_rx_airtime(struct ieee80211_hw *hw,
67 + struct ieee80211_rx_status *status,
68 + int len)
69 +{
70 + struct ieee80211_supported_band *sband;
71 + u32 duration, overhead = 0;
72 +
73 + if (status->encoding == RX_ENC_LEGACY) {
74 + const struct ieee80211_rate *rate;
75 + bool sp = status->enc_flags & RX_ENC_FLAG_SHORTPRE;
76 + bool cck;
77 +
78 + if (WARN_ON_ONCE(status->band > NL80211_BAND_5GHZ))
79 + return 0;
80 +
81 + sband = hw->wiphy->bands[status->band];
82 + if (!sband || status->rate_idx >= sband->n_bitrates)
83 + return 0;
84 +
85 + rate = &sband->bitrates[status->rate_idx];
86 + cck = rate->flags & IEEE80211_RATE_MANDATORY_B;
87 +
88 + return ieee80211_calc_legacy_rate_duration(rate->bitrate, sp,
89 + cck, len);
90 + }
91 +
92 + duration = ieee80211_get_rate_duration(hw, status, &overhead);
93 + if (!duration)
94 + return 0;
95 +
96 duration *= len;
97 duration /= AVG_PKT_SIZE;
98 duration /= 1024;
99
100 - duration += 36 + (streams << 2);
101 -
102 - return duration;
103 + return duration + overhead;
104 }
105 EXPORT_SYMBOL_GPL(ieee80211_calc_rx_airtime);
106
107 @@ -530,46 +546,57 @@ static bool ieee80211_fill_rate_info(str
108 return false;
109 }
110
111 -static u32 ieee80211_calc_tx_airtime_rate(struct ieee80211_hw *hw,
112 - struct ieee80211_tx_rate *rate,
113 - struct rate_info *ri,
114 - u8 band, int len)
115 +static int ieee80211_fill_rx_status(struct ieee80211_rx_status *stat,
116 + struct ieee80211_hw *hw,
117 + struct ieee80211_tx_rate *rate,
118 + struct rate_info *ri, u8 band, int len)
119 {
120 - struct ieee80211_rx_status stat = {
121 - .band = band,
122 - };
123 + memset(stat, 0, sizeof(*stat));
124 + stat->band = band;
125
126 - if (ieee80211_fill_rate_info(hw, &stat, band, ri))
127 - goto out;
128 + if (ieee80211_fill_rate_info(hw, stat, band, ri))
129 + return 0;
130
131 if (rate->idx < 0 || !rate->count)
132 - return 0;
133 + return -1;
134
135 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
136 - stat.bw = RATE_INFO_BW_80;
137 + stat->bw = RATE_INFO_BW_80;
138 else if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
139 - stat.bw = RATE_INFO_BW_40;
140 + stat->bw = RATE_INFO_BW_40;
141 else
142 - stat.bw = RATE_INFO_BW_20;
143 + stat->bw = RATE_INFO_BW_20;
144
145 - stat.enc_flags = 0;
146 + stat->enc_flags = 0;
147 if (rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
148 - stat.enc_flags |= RX_ENC_FLAG_SHORTPRE;
149 + stat->enc_flags |= RX_ENC_FLAG_SHORTPRE;
150 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
151 - stat.enc_flags |= RX_ENC_FLAG_SHORT_GI;
152 + stat->enc_flags |= RX_ENC_FLAG_SHORT_GI;
153
154 - stat.rate_idx = rate->idx;
155 + stat->rate_idx = rate->idx;
156 if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
157 - stat.encoding = RX_ENC_VHT;
158 - stat.rate_idx = ieee80211_rate_get_vht_mcs(rate);
159 - stat.nss = ieee80211_rate_get_vht_nss(rate);
160 + stat->encoding = RX_ENC_VHT;
161 + stat->rate_idx = ieee80211_rate_get_vht_mcs(rate);
162 + stat->nss = ieee80211_rate_get_vht_nss(rate);
163 } else if (rate->flags & IEEE80211_TX_RC_MCS) {
164 - stat.encoding = RX_ENC_HT;
165 + stat->encoding = RX_ENC_HT;
166 } else {
167 - stat.encoding = RX_ENC_LEGACY;
168 + stat->encoding = RX_ENC_LEGACY;
169 }
170
171 -out:
172 + return 0;
173 +}
174 +
175 +static u32 ieee80211_calc_tx_airtime_rate(struct ieee80211_hw *hw,
176 + struct ieee80211_tx_rate *rate,
177 + struct rate_info *ri,
178 + u8 band, int len)
179 +{
180 + struct ieee80211_rx_status stat;
181 +
182 + if (ieee80211_fill_rx_status(&stat, hw, rate, ri, band, len))
183 + return 0;
184 +
185 return ieee80211_calc_rx_airtime(hw, &stat, len);
186 }
187