aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211/rate.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/mac80211/rate.c')
-rw-r--r--net/mac80211/rate.c63
1 files changed, 52 insertions, 11 deletions
diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
index 6349e7f4dcae..c74b7c85403c 100644
--- a/net/mac80211/rate.c
+++ b/net/mac80211/rate.c
@@ -249,6 +249,38 @@ bool rate_control_send_low(struct ieee80211_sta *sta,
249} 249}
250EXPORT_SYMBOL(rate_control_send_low); 250EXPORT_SYMBOL(rate_control_send_low);
251 251
252static void rate_idx_match_mask(struct ieee80211_tx_rate *rate,
253 int n_bitrates, u32 mask)
254{
255 int j;
256
257 /* See whether the selected rate or anything below it is allowed. */
258 for (j = rate->idx; j >= 0; j--) {
259 if (mask & (1 << j)) {
260 /* Okay, found a suitable rate. Use it. */
261 rate->idx = j;
262 return;
263 }
264 }
265
266 /* Try to find a higher rate that would be allowed */
267 for (j = rate->idx + 1; j < n_bitrates; j++) {
268 if (mask & (1 << j)) {
269 /* Okay, found a suitable rate. Use it. */
270 rate->idx = j;
271 return;
272 }
273 }
274
275 /*
276 * Uh.. No suitable rate exists. This should not really happen with
277 * sane TX rate mask configurations. However, should someone manage to
278 * configure supported rates and TX rate mask in incompatible way,
279 * allow the frame to be transmitted with whatever the rate control
280 * selected.
281 */
282}
283
252void rate_control_get_rate(struct ieee80211_sub_if_data *sdata, 284void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
253 struct sta_info *sta, 285 struct sta_info *sta,
254 struct ieee80211_tx_rate_control *txrc) 286 struct ieee80211_tx_rate_control *txrc)
@@ -258,6 +290,7 @@ void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
258 struct ieee80211_sta *ista = NULL; 290 struct ieee80211_sta *ista = NULL;
259 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb); 291 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
260 int i; 292 int i;
293 u32 mask;
261 294
262 if (sta) { 295 if (sta) {
263 ista = &sta->sta; 296 ista = &sta->sta;
@@ -270,23 +303,31 @@ void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
270 info->control.rates[i].count = 1; 303 info->control.rates[i].count = 1;
271 } 304 }
272 305
273 if (sta && sdata->force_unicast_rateidx > -1) { 306 ref->ops->get_rate(ref->priv, ista, priv_sta, txrc);
274 info->control.rates[0].idx = sdata->force_unicast_rateidx;
275 } else {
276 ref->ops->get_rate(ref->priv, ista, priv_sta, txrc);
277 info->flags |= IEEE80211_TX_INTFL_RCALGO;
278 }
279 307
280 /* 308 /*
281 * try to enforce the maximum rate the user wanted 309 * Try to enforce the rateidx mask the user wanted. skip this if the
310 * default mask (allow all rates) is used to save some processing for
311 * the common case.
282 */ 312 */
283 if (sdata->max_ratectrl_rateidx > -1) 313 mask = sdata->rc_rateidx_mask[info->band];
314 if (mask != (1 << txrc->sband->n_bitrates) - 1) {
315 if (sta) {
316 /* Filter out rates that the STA does not support */
317 mask &= sta->sta.supp_rates[info->band];
318 }
319 /*
320 * Make sure the rate index selected for each TX rate is
321 * included in the configured mask and change the rate indexes
322 * if needed.
323 */
284 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { 324 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
325 /* Rate masking supports only legacy rates for now */
285 if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) 326 if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS)
286 continue; 327 continue;
287 info->control.rates[i].idx = 328 rate_idx_match_mask(&info->control.rates[i],
288 min_t(s8, info->control.rates[i].idx, 329 txrc->sband->n_bitrates, mask);
289 sdata->max_ratectrl_rateidx); 330 }
290 } 331 }
291 332
292 BUG_ON(info->control.rates[0].idx < 0); 333 BUG_ON(info->control.rates[0].idx < 0);