diff options
Diffstat (limited to 'net/mac80211/rate.c')
-rw-r--r-- | net/mac80211/rate.c | 324 |
1 files changed, 268 insertions, 56 deletions
diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c index dd88381c53b7..0d51877efdb7 100644 --- a/net/mac80211/rate.c +++ b/net/mac80211/rate.c | |||
@@ -252,6 +252,25 @@ rate_lowest_non_cck_index(struct ieee80211_supported_band *sband, | |||
252 | return 0; | 252 | return 0; |
253 | } | 253 | } |
254 | 254 | ||
255 | static void __rate_control_send_low(struct ieee80211_hw *hw, | ||
256 | struct ieee80211_supported_band *sband, | ||
257 | struct ieee80211_sta *sta, | ||
258 | struct ieee80211_tx_info *info) | ||
259 | { | ||
260 | if ((sband->band != IEEE80211_BAND_2GHZ) || | ||
261 | !(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)) | ||
262 | info->control.rates[0].idx = rate_lowest_index(sband, sta); | ||
263 | else | ||
264 | info->control.rates[0].idx = | ||
265 | rate_lowest_non_cck_index(sband, sta); | ||
266 | |||
267 | info->control.rates[0].count = | ||
268 | (info->flags & IEEE80211_TX_CTL_NO_ACK) ? | ||
269 | 1 : hw->max_rate_tries; | ||
270 | |||
271 | info->control.skip_table = 1; | ||
272 | } | ||
273 | |||
255 | 274 | ||
256 | bool rate_control_send_low(struct ieee80211_sta *sta, | 275 | bool rate_control_send_low(struct ieee80211_sta *sta, |
257 | void *priv_sta, | 276 | void *priv_sta, |
@@ -262,16 +281,8 @@ bool rate_control_send_low(struct ieee80211_sta *sta, | |||
262 | int mcast_rate; | 281 | int mcast_rate; |
263 | 282 | ||
264 | if (!sta || !priv_sta || rc_no_data_or_no_ack_use_min(txrc)) { | 283 | if (!sta || !priv_sta || rc_no_data_or_no_ack_use_min(txrc)) { |
265 | if ((sband->band != IEEE80211_BAND_2GHZ) || | 284 | __rate_control_send_low(txrc->hw, sband, sta, info); |
266 | !(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)) | 285 | |
267 | info->control.rates[0].idx = | ||
268 | rate_lowest_index(txrc->sband, sta); | ||
269 | else | ||
270 | info->control.rates[0].idx = | ||
271 | rate_lowest_non_cck_index(txrc->sband, sta); | ||
272 | info->control.rates[0].count = | ||
273 | (info->flags & IEEE80211_TX_CTL_NO_ACK) ? | ||
274 | 1 : txrc->hw->max_rate_tries; | ||
275 | if (!sta && txrc->bss) { | 286 | if (!sta && txrc->bss) { |
276 | mcast_rate = txrc->bss_conf->mcast_rate[sband->band]; | 287 | mcast_rate = txrc->bss_conf->mcast_rate[sband->band]; |
277 | if (mcast_rate > 0) { | 288 | if (mcast_rate > 0) { |
@@ -355,7 +366,8 @@ static bool rate_idx_match_mcs_mask(struct ieee80211_tx_rate *rate, | |||
355 | 366 | ||
356 | 367 | ||
357 | static void rate_idx_match_mask(struct ieee80211_tx_rate *rate, | 368 | static void rate_idx_match_mask(struct ieee80211_tx_rate *rate, |
358 | struct ieee80211_tx_rate_control *txrc, | 369 | struct ieee80211_supported_band *sband, |
370 | enum nl80211_chan_width chan_width, | ||
359 | u32 mask, | 371 | u32 mask, |
360 | u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN]) | 372 | u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN]) |
361 | { | 373 | { |
@@ -375,27 +387,17 @@ static void rate_idx_match_mask(struct ieee80211_tx_rate *rate, | |||
375 | IEEE80211_TX_RC_USE_SHORT_PREAMBLE); | 387 | IEEE80211_TX_RC_USE_SHORT_PREAMBLE); |
376 | alt_rate.count = rate->count; | 388 | alt_rate.count = rate->count; |
377 | if (rate_idx_match_legacy_mask(&alt_rate, | 389 | if (rate_idx_match_legacy_mask(&alt_rate, |
378 | txrc->sband->n_bitrates, | 390 | sband->n_bitrates, mask)) { |
379 | mask)) { | ||
380 | *rate = alt_rate; | 391 | *rate = alt_rate; |
381 | return; | 392 | return; |
382 | } | 393 | } |
383 | } else { | 394 | } else { |
384 | struct sk_buff *skb = txrc->skb; | ||
385 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | ||
386 | __le16 fc; | ||
387 | |||
388 | /* handle legacy rates */ | 395 | /* handle legacy rates */ |
389 | if (rate_idx_match_legacy_mask(rate, txrc->sband->n_bitrates, | 396 | if (rate_idx_match_legacy_mask(rate, sband->n_bitrates, mask)) |
390 | mask)) | ||
391 | return; | 397 | return; |
392 | 398 | ||
393 | /* if HT BSS, and we handle a data frame, also try HT rates */ | 399 | /* if HT BSS, and we handle a data frame, also try HT rates */ |
394 | if (txrc->bss_conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT) | 400 | if (chan_width == NL80211_CHAN_WIDTH_20_NOHT) |
395 | return; | ||
396 | |||
397 | fc = hdr->frame_control; | ||
398 | if (!ieee80211_is_data(fc)) | ||
399 | return; | 401 | return; |
400 | 402 | ||
401 | alt_rate.idx = 0; | 403 | alt_rate.idx = 0; |
@@ -408,7 +410,7 @@ static void rate_idx_match_mask(struct ieee80211_tx_rate *rate, | |||
408 | 410 | ||
409 | alt_rate.flags |= IEEE80211_TX_RC_MCS; | 411 | alt_rate.flags |= IEEE80211_TX_RC_MCS; |
410 | 412 | ||
411 | if (txrc->bss_conf->chandef.width == NL80211_CHAN_WIDTH_40) | 413 | if (chan_width == NL80211_CHAN_WIDTH_40) |
412 | alt_rate.flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; | 414 | alt_rate.flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; |
413 | 415 | ||
414 | if (rate_idx_match_mcs_mask(&alt_rate, mcs_mask)) { | 416 | if (rate_idx_match_mcs_mask(&alt_rate, mcs_mask)) { |
@@ -426,6 +428,228 @@ static void rate_idx_match_mask(struct ieee80211_tx_rate *rate, | |||
426 | */ | 428 | */ |
427 | } | 429 | } |
428 | 430 | ||
431 | static void rate_fixup_ratelist(struct ieee80211_vif *vif, | ||
432 | struct ieee80211_supported_band *sband, | ||
433 | struct ieee80211_tx_info *info, | ||
434 | struct ieee80211_tx_rate *rates, | ||
435 | int max_rates) | ||
436 | { | ||
437 | struct ieee80211_rate *rate; | ||
438 | bool inval = false; | ||
439 | int i; | ||
440 | |||
441 | /* | ||
442 | * Set up the RTS/CTS rate as the fastest basic rate | ||
443 | * that is not faster than the data rate unless there | ||
444 | * is no basic rate slower than the data rate, in which | ||
445 | * case we pick the slowest basic rate | ||
446 | * | ||
447 | * XXX: Should this check all retry rates? | ||
448 | */ | ||
449 | if (!(rates[0].flags & IEEE80211_TX_RC_MCS)) { | ||
450 | u32 basic_rates = vif->bss_conf.basic_rates; | ||
451 | s8 baserate = basic_rates ? ffs(basic_rates - 1) : 0; | ||
452 | |||
453 | rate = &sband->bitrates[rates[0].idx]; | ||
454 | |||
455 | for (i = 0; i < sband->n_bitrates; i++) { | ||
456 | /* must be a basic rate */ | ||
457 | if (!(basic_rates & BIT(i))) | ||
458 | continue; | ||
459 | /* must not be faster than the data rate */ | ||
460 | if (sband->bitrates[i].bitrate > rate->bitrate) | ||
461 | continue; | ||
462 | /* maximum */ | ||
463 | if (sband->bitrates[baserate].bitrate < | ||
464 | sband->bitrates[i].bitrate) | ||
465 | baserate = i; | ||
466 | } | ||
467 | |||
468 | info->control.rts_cts_rate_idx = baserate; | ||
469 | } | ||
470 | |||
471 | for (i = 0; i < max_rates; i++) { | ||
472 | /* | ||
473 | * make sure there's no valid rate following | ||
474 | * an invalid one, just in case drivers don't | ||
475 | * take the API seriously to stop at -1. | ||
476 | */ | ||
477 | if (inval) { | ||
478 | rates[i].idx = -1; | ||
479 | continue; | ||
480 | } | ||
481 | if (rates[i].idx < 0) { | ||
482 | inval = true; | ||
483 | continue; | ||
484 | } | ||
485 | |||
486 | /* | ||
487 | * For now assume MCS is already set up correctly, this | ||
488 | * needs to be fixed. | ||
489 | */ | ||
490 | if (rates[i].flags & IEEE80211_TX_RC_MCS) { | ||
491 | WARN_ON(rates[i].idx > 76); | ||
492 | |||
493 | if (!(rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) && | ||
494 | info->control.use_cts_prot) | ||
495 | rates[i].flags |= | ||
496 | IEEE80211_TX_RC_USE_CTS_PROTECT; | ||
497 | continue; | ||
498 | } | ||
499 | |||
500 | if (rates[i].flags & IEEE80211_TX_RC_VHT_MCS) { | ||
501 | WARN_ON(ieee80211_rate_get_vht_mcs(&rates[i]) > 9); | ||
502 | continue; | ||
503 | } | ||
504 | |||
505 | /* set up RTS protection if desired */ | ||
506 | if (info->control.use_rts) { | ||
507 | rates[i].flags |= IEEE80211_TX_RC_USE_RTS_CTS; | ||
508 | info->control.use_cts_prot = false; | ||
509 | } | ||
510 | |||
511 | /* RC is busted */ | ||
512 | if (WARN_ON_ONCE(rates[i].idx >= sband->n_bitrates)) { | ||
513 | rates[i].idx = -1; | ||
514 | continue; | ||
515 | } | ||
516 | |||
517 | rate = &sband->bitrates[rates[i].idx]; | ||
518 | |||
519 | /* set up short preamble */ | ||
520 | if (info->control.short_preamble && | ||
521 | rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) | ||
522 | rates[i].flags |= IEEE80211_TX_RC_USE_SHORT_PREAMBLE; | ||
523 | |||
524 | /* set up G protection */ | ||
525 | if (!(rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) && | ||
526 | info->control.use_cts_prot && | ||
527 | rate->flags & IEEE80211_RATE_ERP_G) | ||
528 | rates[i].flags |= IEEE80211_TX_RC_USE_CTS_PROTECT; | ||
529 | } | ||
530 | } | ||
531 | |||
532 | |||
533 | static void rate_control_fill_sta_table(struct ieee80211_sta *sta, | ||
534 | struct ieee80211_tx_info *info, | ||
535 | struct ieee80211_tx_rate *rates, | ||
536 | int max_rates) | ||
537 | { | ||
538 | struct ieee80211_sta_rates *ratetbl = NULL; | ||
539 | int i; | ||
540 | |||
541 | if (sta && !info->control.skip_table) | ||
542 | ratetbl = rcu_dereference(sta->rates); | ||
543 | |||
544 | /* Fill remaining rate slots with data from the sta rate table. */ | ||
545 | max_rates = min_t(int, max_rates, IEEE80211_TX_RATE_TABLE_SIZE); | ||
546 | for (i = 0; i < max_rates; i++) { | ||
547 | if (i < ARRAY_SIZE(info->control.rates) && | ||
548 | info->control.rates[i].idx >= 0 && | ||
549 | info->control.rates[i].count) { | ||
550 | if (rates != info->control.rates) | ||
551 | rates[i] = info->control.rates[i]; | ||
552 | } else if (ratetbl) { | ||
553 | rates[i].idx = ratetbl->rate[i].idx; | ||
554 | rates[i].flags = ratetbl->rate[i].flags; | ||
555 | if (info->control.use_rts) | ||
556 | rates[i].count = ratetbl->rate[i].count_rts; | ||
557 | else if (info->control.use_cts_prot) | ||
558 | rates[i].count = ratetbl->rate[i].count_cts; | ||
559 | else | ||
560 | rates[i].count = ratetbl->rate[i].count; | ||
561 | } else { | ||
562 | rates[i].idx = -1; | ||
563 | rates[i].count = 0; | ||
564 | } | ||
565 | |||
566 | if (rates[i].idx < 0 || !rates[i].count) | ||
567 | break; | ||
568 | } | ||
569 | } | ||
570 | |||
571 | static void rate_control_apply_mask(struct ieee80211_sub_if_data *sdata, | ||
572 | struct ieee80211_sta *sta, | ||
573 | struct ieee80211_supported_band *sband, | ||
574 | struct ieee80211_tx_info *info, | ||
575 | struct ieee80211_tx_rate *rates, | ||
576 | int max_rates) | ||
577 | { | ||
578 | enum nl80211_chan_width chan_width; | ||
579 | u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN]; | ||
580 | bool has_mcs_mask; | ||
581 | u32 mask; | ||
582 | int i; | ||
583 | |||
584 | /* | ||
585 | * Try to enforce the rateidx mask the user wanted. skip this if the | ||
586 | * default mask (allow all rates) is used to save some processing for | ||
587 | * the common case. | ||
588 | */ | ||
589 | mask = sdata->rc_rateidx_mask[info->band]; | ||
590 | has_mcs_mask = sdata->rc_has_mcs_mask[info->band]; | ||
591 | if (mask == (1 << sband->n_bitrates) - 1 && !has_mcs_mask) | ||
592 | return; | ||
593 | |||
594 | if (has_mcs_mask) | ||
595 | memcpy(mcs_mask, sdata->rc_rateidx_mcs_mask[info->band], | ||
596 | sizeof(mcs_mask)); | ||
597 | else | ||
598 | memset(mcs_mask, 0xff, sizeof(mcs_mask)); | ||
599 | |||
600 | if (sta) { | ||
601 | /* Filter out rates that the STA does not support */ | ||
602 | mask &= sta->supp_rates[info->band]; | ||
603 | for (i = 0; i < sizeof(mcs_mask); i++) | ||
604 | mcs_mask[i] &= sta->ht_cap.mcs.rx_mask[i]; | ||
605 | } | ||
606 | |||
607 | /* | ||
608 | * Make sure the rate index selected for each TX rate is | ||
609 | * included in the configured mask and change the rate indexes | ||
610 | * if needed. | ||
611 | */ | ||
612 | chan_width = sdata->vif.bss_conf.chandef.width; | ||
613 | for (i = 0; i < max_rates; i++) { | ||
614 | /* Skip invalid rates */ | ||
615 | if (rates[i].idx < 0) | ||
616 | break; | ||
617 | |||
618 | rate_idx_match_mask(&rates[i], sband, mask, chan_width, | ||
619 | mcs_mask); | ||
620 | } | ||
621 | } | ||
622 | |||
623 | void ieee80211_get_tx_rates(struct ieee80211_vif *vif, | ||
624 | struct ieee80211_sta *sta, | ||
625 | struct sk_buff *skb, | ||
626 | struct ieee80211_tx_rate *dest, | ||
627 | int max_rates) | ||
628 | { | ||
629 | struct ieee80211_sub_if_data *sdata; | ||
630 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | ||
631 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | ||
632 | struct ieee80211_supported_band *sband; | ||
633 | |||
634 | rate_control_fill_sta_table(sta, info, dest, max_rates); | ||
635 | |||
636 | if (!vif) | ||
637 | return; | ||
638 | |||
639 | sdata = vif_to_sdata(vif); | ||
640 | sband = sdata->local->hw.wiphy->bands[info->band]; | ||
641 | |||
642 | if (ieee80211_is_data(hdr->frame_control)) | ||
643 | rate_control_apply_mask(sdata, sta, sband, info, dest, max_rates); | ||
644 | |||
645 | if (dest[0].idx < 0) | ||
646 | __rate_control_send_low(&sdata->local->hw, sband, sta, info); | ||
647 | |||
648 | if (sta) | ||
649 | rate_fixup_ratelist(vif, sband, info, dest, max_rates); | ||
650 | } | ||
651 | EXPORT_SYMBOL(ieee80211_get_tx_rates); | ||
652 | |||
429 | void rate_control_get_rate(struct ieee80211_sub_if_data *sdata, | 653 | void rate_control_get_rate(struct ieee80211_sub_if_data *sdata, |
430 | struct sta_info *sta, | 654 | struct sta_info *sta, |
431 | struct ieee80211_tx_rate_control *txrc) | 655 | struct ieee80211_tx_rate_control *txrc) |
@@ -435,8 +659,6 @@ void rate_control_get_rate(struct ieee80211_sub_if_data *sdata, | |||
435 | struct ieee80211_sta *ista = NULL; | 659 | struct ieee80211_sta *ista = NULL; |
436 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb); | 660 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb); |
437 | int i; | 661 | int i; |
438 | u32 mask; | ||
439 | u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN]; | ||
440 | 662 | ||
441 | if (sta && test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) { | 663 | if (sta && test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) { |
442 | ista = &sta->sta; | 664 | ista = &sta->sta; |
@@ -454,37 +676,27 @@ void rate_control_get_rate(struct ieee80211_sub_if_data *sdata, | |||
454 | 676 | ||
455 | ref->ops->get_rate(ref->priv, ista, priv_sta, txrc); | 677 | ref->ops->get_rate(ref->priv, ista, priv_sta, txrc); |
456 | 678 | ||
457 | /* | 679 | if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_RC_TABLE) |
458 | * Try to enforce the rateidx mask the user wanted. skip this if the | 680 | return; |
459 | * default mask (allow all rates) is used to save some processing for | 681 | |
460 | * the common case. | 682 | ieee80211_get_tx_rates(&sdata->vif, ista, txrc->skb, |
461 | */ | 683 | info->control.rates, |
462 | mask = sdata->rc_rateidx_mask[info->band]; | 684 | ARRAY_SIZE(info->control.rates)); |
463 | memcpy(mcs_mask, sdata->rc_rateidx_mcs_mask[info->band], | 685 | } |
464 | sizeof(mcs_mask)); | ||
465 | if (mask != (1 << txrc->sband->n_bitrates) - 1) { | ||
466 | if (sta) { | ||
467 | /* Filter out rates that the STA does not support */ | ||
468 | mask &= sta->sta.supp_rates[info->band]; | ||
469 | for (i = 0; i < sizeof(mcs_mask); i++) | ||
470 | mcs_mask[i] &= sta->sta.ht_cap.mcs.rx_mask[i]; | ||
471 | } | ||
472 | /* | ||
473 | * Make sure the rate index selected for each TX rate is | ||
474 | * included in the configured mask and change the rate indexes | ||
475 | * if needed. | ||
476 | */ | ||
477 | for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { | ||
478 | /* Skip invalid rates */ | ||
479 | if (info->control.rates[i].idx < 0) | ||
480 | break; | ||
481 | rate_idx_match_mask(&info->control.rates[i], txrc, | ||
482 | mask, mcs_mask); | ||
483 | } | ||
484 | } | ||
485 | 686 | ||
486 | BUG_ON(info->control.rates[0].idx < 0); | 687 | int rate_control_set_rates(struct ieee80211_hw *hw, |
688 | struct ieee80211_sta *pubsta, | ||
689 | struct ieee80211_sta_rates *rates) | ||
690 | { | ||
691 | struct ieee80211_sta_rates *old = rcu_dereference(pubsta->rates); | ||
692 | |||
693 | rcu_assign_pointer(pubsta->rates, rates); | ||
694 | if (old) | ||
695 | kfree_rcu(old, rcu_head); | ||
696 | |||
697 | return 0; | ||
487 | } | 698 | } |
699 | EXPORT_SYMBOL(rate_control_set_rates); | ||
488 | 700 | ||
489 | int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local, | 701 | int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local, |
490 | const char *name) | 702 | const char *name) |