Lines Matching +full:out +full:- +full:of +full:- +full:band
1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved.
8 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 #define RS_NAME "iwl-3945-rs"
50 {-60, RATE_54M_IDX},
51 {-64, RATE_48M_IDX},
52 {-72, RATE_36M_IDX},
53 {-80, RATE_24M_IDX},
54 {-84, RATE_18M_IDX},
55 {-85, RATE_12M_IDX},
56 {-87, RATE_9M_IDX},
57 {-89, RATE_6M_IDX}
61 {-60, RATE_54M_IDX},
62 {-64, RATE_48M_IDX},
63 {-68, RATE_36M_IDX},
64 {-80, RATE_24M_IDX},
65 {-84, RATE_18M_IDX},
66 {-85, RATE_12M_IDX},
67 {-86, RATE_11M_IDX},
68 {-88, RATE_5M_IDX},
69 {-90, RATE_2M_IDX},
70 {-92, RATE_1M_IDX}
85 il3945_get_rate_idx_by_rssi(s32 rssi, enum nl80211_band band) in il3945_get_rate_idx_by_rssi() argument
94 switch (band) { in il3945_get_rate_idx_by_rssi()
111 idx = min(idx, table_size - 1); in il3945_get_rate_idx_by_rssi()
119 win->data = 0; in il3945_clear_win()
120 win->success_counter = 0; in il3945_clear_win()
121 win->success_ratio = -1; in il3945_clear_win()
122 win->counter = 0; in il3945_clear_win()
123 win->average_tpt = IL_INVALID_VALUE; in il3945_clear_win()
124 win->stamp = 0; in il3945_clear_win()
128 * il3945_rate_scale_flush_wins - flush out the rate scale wins
130 * Returns the number of wins that have gathered data but were
140 struct il_priv *il __maybe_unused = rs_sta->il; in il3945_rate_scale_flush_wins()
145 * since we flushed, clear out the gathered stats in il3945_rate_scale_flush_wins()
148 if (!rs_sta->win[i].counter) in il3945_rate_scale_flush_wins()
151 spin_lock_irqsave(&rs_sta->lock, flags); in il3945_rate_scale_flush_wins()
152 if (time_after(jiffies, rs_sta->win[i].stamp + RATE_WIN_FLUSH)) { in il3945_rate_scale_flush_wins()
153 D_RATE("flushing %d samples of rate " "idx %d\n", in il3945_rate_scale_flush_wins()
154 rs_sta->win[i].counter, i); in il3945_rate_scale_flush_wins()
155 il3945_clear_win(&rs_sta->win[i]); in il3945_rate_scale_flush_wins()
158 spin_unlock_irqrestore(&rs_sta->lock, flags); in il3945_rate_scale_flush_wins()
172 struct il_priv *il __maybe_unused = rs_sta->il; in il3945_bg_rate_scale_flush()
181 spin_lock_irqsave(&rs_sta->lock, flags); in il3945_bg_rate_scale_flush()
183 /* Number of packets Rx'd since last time this timer ran */ in il3945_bg_rate_scale_flush()
184 packet_count = (rs_sta->tx_packets - rs_sta->last_tx_packets) + 1; in il3945_bg_rate_scale_flush()
186 rs_sta->last_tx_packets = rs_sta->tx_packets + 1; in il3945_bg_rate_scale_flush()
190 jiffies_to_msecs(jiffies - rs_sta->last_partial_flush); in il3945_bg_rate_scale_flush()
209 rs_sta->flush_time = msecs_to_jiffies(duration); in il3945_bg_rate_scale_flush()
214 mod_timer(&rs_sta->rate_scale_flush, in il3945_bg_rate_scale_flush()
215 jiffies + rs_sta->flush_time); in il3945_bg_rate_scale_flush()
217 rs_sta->last_partial_flush = jiffies; in il3945_bg_rate_scale_flush()
219 rs_sta->flush_time = RATE_FLUSH; in il3945_bg_rate_scale_flush()
220 rs_sta->flush_pending = 0; in il3945_bg_rate_scale_flush()
225 rs_sta->last_flush = jiffies; in il3945_bg_rate_scale_flush()
227 spin_unlock_irqrestore(&rs_sta->lock, flags); in il3945_bg_rate_scale_flush()
233 * il3945_collect_tx_data - Update the success/failure sliding win
235 * We keep a sliding win of the last 64 packets transmitted
236 * at this rate. win->data contains the bitmask of successful
246 struct il_priv *il __maybe_unused = rs_sta->il; in il3945_collect_tx_data()
249 D_RATE("leave: retries == 0 -- should be at least 1\n"); in il3945_collect_tx_data()
253 spin_lock_irqsave(&rs_sta->lock, flags); in il3945_collect_tx_data()
256 * Keep track of only the latest 62 tx frame attempts in this rate's in il3945_collect_tx_data()
264 if (win->counter >= RATE_MAX_WINDOW) { in il3945_collect_tx_data()
267 win->counter = RATE_MAX_WINDOW - 1; in il3945_collect_tx_data()
269 if (win->data & (1ULL << (RATE_MAX_WINDOW - 1))) { in il3945_collect_tx_data()
270 win->data &= ~(1ULL << (RATE_MAX_WINDOW - 1)); in il3945_collect_tx_data()
271 win->success_counter--; in il3945_collect_tx_data()
275 /* Increment frames-attempted counter */ in il3945_collect_tx_data()
276 win->counter++; in il3945_collect_tx_data()
281 win->data <<= 1; in il3945_collect_tx_data()
283 win->success_counter++; in il3945_collect_tx_data()
284 win->data |= 0x1; in il3945_collect_tx_data()
285 success--; in il3945_collect_tx_data()
288 retries--; in il3945_collect_tx_data()
291 /* Calculate current success ratio, avoid divide-by-0! */ in il3945_collect_tx_data()
292 if (win->counter > 0) in il3945_collect_tx_data()
293 win->success_ratio = in il3945_collect_tx_data()
294 128 * (100 * win->success_counter) / win->counter; in il3945_collect_tx_data()
296 win->success_ratio = IL_INVALID_VALUE; in il3945_collect_tx_data()
298 fail_count = win->counter - win->success_counter; in il3945_collect_tx_data()
302 win->success_counter >= RATE_MIN_SUCCESS_TH) in il3945_collect_tx_data()
303 win->average_tpt = in il3945_collect_tx_data()
304 ((win->success_ratio * rs_sta->expected_tpt[idx] + in il3945_collect_tx_data()
307 win->average_tpt = IL_INVALID_VALUE; in il3945_collect_tx_data()
310 win->stamp = jiffies; in il3945_collect_tx_data()
312 spin_unlock_irqrestore(&rs_sta->lock, flags); in il3945_collect_tx_data()
321 struct ieee80211_hw *hw = il->hw; in il3945_rs_rate_init()
322 struct ieee80211_conf *conf = &il->hw->conf; in il3945_rs_rate_init()
329 if (sta_id == il->hw_params.bcast_id) in il3945_rs_rate_init()
330 goto out; in il3945_rs_rate_init()
332 psta = (struct il3945_sta_priv *)sta->drv_priv; in il3945_rs_rate_init()
333 rs_sta = &psta->rs_sta; in il3945_rs_rate_init()
334 sband = hw->wiphy->bands[conf->chandef.chan->band]; in il3945_rs_rate_init()
336 rs_sta->il = il; in il3945_rs_rate_init()
338 rs_sta->start_rate = RATE_INVALID; in il3945_rs_rate_init()
341 rs_sta->expected_tpt = il3945_expected_tpt_b; in il3945_rs_rate_init()
343 rs_sta->last_partial_flush = jiffies; in il3945_rs_rate_init()
344 rs_sta->last_flush = jiffies; in il3945_rs_rate_init()
345 rs_sta->flush_time = RATE_FLUSH; in il3945_rs_rate_init()
346 rs_sta->last_tx_packets = 0; in il3945_rs_rate_init()
349 il3945_clear_win(&rs_sta->win[i]); in il3945_rs_rate_init()
356 for (i = sband->n_bitrates - 1; i >= 0; i--) { in il3945_rs_rate_init()
357 if (sta->supp_rates[sband->band] & (1 << i)) { in il3945_rs_rate_init()
358 rs_sta->last_txrate_idx = i; in il3945_rs_rate_init()
363 il->_3945.sta_supp_rates = sta->supp_rates[sband->band]; in il3945_rs_rate_init()
364 /* For 5 GHz band it start at IL_FIRST_OFDM_RATE */ in il3945_rs_rate_init()
365 if (sband->band == NL80211_BAND_5GHZ) { in il3945_rs_rate_init()
366 rs_sta->last_txrate_idx += IL_FIRST_OFDM_RATE; in il3945_rs_rate_init()
367 il->_3945.sta_supp_rates <<= IL_FIRST_OFDM_RATE; in il3945_rs_rate_init()
370 out: in il3945_rs_rate_init()
371 il->stations[sta_id].used &= ~IL_STA_UCODE_INPROGRESS; in il3945_rs_rate_init()
379 return hw->priv; in il3945_rs_alloc()
392 struct il3945_sta_priv *psta = (void *)sta->drv_priv; in il3945_rs_alloc_sta()
397 rs_sta = &psta->rs_sta; in il3945_rs_alloc_sta()
399 spin_lock_init(&rs_sta->lock); in il3945_rs_alloc_sta()
400 timer_setup(&rs_sta->rate_scale_flush, il3945_bg_rate_scale_flush, 0); in il3945_rs_alloc_sta()
412 * Be careful not to use any members of il3945_rs_sta (like trying in il3945_rs_free_sta()
413 * to use il_priv to print out debugging) since it may not be fully in il3945_rs_free_sta()
416 del_timer_sync(&rs_sta->rate_scale_flush); in il3945_rs_free_sta()
420 * il3945_rs_tx_status - Update rate control values based on Tx results
422 * NOTE: Uses il_priv->retry_rate for the # of retries attempted by
439 retries = info->status.rates[0].count; in il3945_rs_tx_status()
444 first_idx = sband->bitrates[info->status.rates[0].idx].hw_value; in il3945_rs_tx_status()
446 D_RATE("leave: Rate out of bounds: %d\n", first_idx); in il3945_rs_tx_status()
455 /* Treat uninitialized rate scaling data same as non-existing. */ in il3945_rs_tx_status()
456 if (!rs_sta->il) { in il3945_rs_tx_status()
461 rs_sta->tx_packets++; in il3945_rs_tx_status()
468 * were Tx'd based on the total number of retries vs. the number in il3945_rs_tx_status()
469 * of retries configured for each rate -- currently set to the in il3945_rs_tx_status()
477 if ((retries - 1) < il->retry_rate) { in il3945_rs_tx_status()
478 current_count = (retries - 1); in il3945_rs_tx_status()
481 current_count = il->retry_rate; in il3945_rs_tx_status()
487 il3945_collect_tx_data(rs_sta, &rs_sta->win[scale_rate_idx], 0, in il3945_rs_tx_status()
492 retries -= current_count; in il3945_rs_tx_status()
499 (info->flags & IEEE80211_TX_STAT_ACK) ? "success" : "failure"); in il3945_rs_tx_status()
500 il3945_collect_tx_data(rs_sta, &rs_sta->win[last_idx], in il3945_rs_tx_status()
501 info->flags & IEEE80211_TX_STAT_ACK, 1, in il3945_rs_tx_status()
504 /* We updated the rate scale win -- if its been more than in il3945_rs_tx_status()
507 spin_lock_irqsave(&rs_sta->lock, flags); in il3945_rs_tx_status()
509 if (!rs_sta->flush_pending && in il3945_rs_tx_status()
510 time_after(jiffies, rs_sta->last_flush + rs_sta->flush_time)) { in il3945_rs_tx_status()
512 rs_sta->last_partial_flush = jiffies; in il3945_rs_tx_status()
513 rs_sta->flush_pending = 1; in il3945_rs_tx_status()
514 mod_timer(&rs_sta->rate_scale_flush, in il3945_rs_tx_status()
515 jiffies + rs_sta->flush_time); in il3945_rs_tx_status()
518 spin_unlock_irqrestore(&rs_sta->lock, flags); in il3945_rs_tx_status()
525 enum nl80211_band band) in il3945_get_adjacent_rate() argument
529 struct il_priv *il __maybe_unused = rs_sta->il; in il3945_get_adjacent_rate()
533 if (unlikely(band == NL80211_BAND_5GHZ)) { in il3945_get_adjacent_rate()
538 i = idx - 1; in il3945_get_adjacent_rate()
539 for (mask = (1 << i); i >= 0; i--, mask >>= 1) { in il3945_get_adjacent_rate()
560 if (rs_sta->tgg) in il3945_get_adjacent_rate()
573 if (rs_sta->tgg) in il3945_get_adjacent_rate()
588 * il3945_rs_get_rate - find the rate for the requested packet
595 * The rate control algorithm uses a single table of rates that goes across
607 struct ieee80211_supported_band *sband = txrc->sband; in il3945_rs_get_rate()
608 struct sk_buff *skb = txrc->skb; in il3945_rs_get_rate()
622 s8 max_rate_idx = -1; in il3945_rs_get_rate()
628 /* Treat uninitialized rate scaling data same as non-existing. */ in il3945_rs_get_rate()
629 if (rs_sta && !rs_sta->il) { in il3945_rs_get_rate()
634 rate_mask = sta->supp_rates[sband->band]; in il3945_rs_get_rate()
637 max_rate_idx = fls(txrc->rate_idx_mask) - 1; in il3945_rs_get_rate()
638 if (sband->band == NL80211_BAND_5GHZ && max_rate_idx != -1) in il3945_rs_get_rate()
641 max_rate_idx = -1; in il3945_rs_get_rate()
643 idx = min(rs_sta->last_txrate_idx & 0xffff, RATE_COUNT_3945 - 1); in il3945_rs_get_rate()
645 if (sband->band == NL80211_BAND_5GHZ) in il3945_rs_get_rate()
648 spin_lock_irqsave(&rs_sta->lock, flags); in il3945_rs_get_rate()
653 if (rs_sta->start_rate != RATE_INVALID) { in il3945_rs_get_rate()
654 if (rs_sta->start_rate < idx && in il3945_rs_get_rate()
655 (rate_mask & (1 << rs_sta->start_rate))) in il3945_rs_get_rate()
656 idx = rs_sta->start_rate; in il3945_rs_get_rate()
657 rs_sta->start_rate = RATE_INVALID; in il3945_rs_get_rate()
661 if (max_rate_idx != -1 && max_rate_idx < idx) { in il3945_rs_get_rate()
666 win = &(rs_sta->win[idx]); in il3945_rs_get_rate()
668 fail_count = win->counter - win->success_counter; in il3945_rs_get_rate()
671 win->success_counter < RATE_MIN_SUCCESS_TH) { in il3945_rs_get_rate()
672 spin_unlock_irqrestore(&rs_sta->lock, flags); in il3945_rs_get_rate()
676 "expected_tpt is %sNULL\n", idx, win->counter, in il3945_rs_get_rate()
677 win->success_counter, in il3945_rs_get_rate()
678 rs_sta->expected_tpt ? "not " : ""); in il3945_rs_get_rate()
681 win->average_tpt = IL_INVALID_VALUE; in il3945_rs_get_rate()
682 goto out; in il3945_rs_get_rate()
686 current_tpt = win->average_tpt; in il3945_rs_get_rate()
689 il3945_get_adjacent_rate(rs_sta, idx, rate_mask, sband->band); in il3945_rs_get_rate()
694 if (max_rate_idx != -1 && max_rate_idx < high) in il3945_rs_get_rate()
697 /* Collect Measured throughputs of adjacent rates */ in il3945_rs_get_rate()
699 low_tpt = rs_sta->win[low].average_tpt; in il3945_rs_get_rate()
702 high_tpt = rs_sta->win[high].average_tpt; in il3945_rs_get_rate()
704 spin_unlock_irqrestore(&rs_sta->lock, flags); in il3945_rs_get_rate()
709 if (win->success_ratio < RATE_DECREASE_TH || !current_tpt) { in il3945_rs_get_rate()
710 D_RATE("decrease rate because of low success_ratio\n"); in il3945_rs_get_rate()
711 scale_action = -1; in il3945_rs_get_rate()
717 win->success_ratio >= RATE_INCREASE_TH) in il3945_rs_get_rate()
728 D_RATE("No action -- low [%d] & high [%d] < " in il3945_rs_get_rate()
732 /* At least one of the rates has better throughput */ in il3945_rs_get_rate()
739 win->success_ratio >= RATE_INCREASE_TH) in il3945_rs_get_rate()
742 D_RATE("decrease rate because of high tpt\n"); in il3945_rs_get_rate()
747 D_RATE("decrease rate because of low tpt\n"); in il3945_rs_get_rate()
748 scale_action = -1; in il3945_rs_get_rate()
749 } else if (win->success_ratio >= RATE_INCREASE_TH) { in il3945_rs_get_rate()
759 if (scale_action == -1 && low != RATE_INVALID && in il3945_rs_get_rate()
760 (win->success_ratio > RATE_HIGH_TH || in il3945_rs_get_rate()
761 current_tpt > 100 * rs_sta->expected_tpt[low])) in il3945_rs_get_rate()
765 case -1: in il3945_rs_get_rate()
782 D_RATE("Selected %d (action %d) - low %d high %d\n", idx, scale_action, in il3945_rs_get_rate()
785 out: in il3945_rs_get_rate()
787 if (sband->band == NL80211_BAND_5GHZ) { in il3945_rs_get_rate()
790 rs_sta->last_txrate_idx = idx; in il3945_rs_get_rate()
791 info->control.rates[0].idx = idx - IL_FIRST_OFDM_RATE; in il3945_rs_get_rate()
793 rs_sta->last_txrate_idx = idx; in il3945_rs_get_rate()
794 info->control.rates[0].idx = rs_sta->last_txrate_idx; in il3945_rs_get_rate()
796 info->control.rates[0].count = 1; in il3945_rs_get_rate()
811 struct il3945_rs_sta *lq_sta = file->private_data; in il3945_sta_dbgfs_stats_table_read()
815 return -ENOMEM; in il3945_sta_dbgfs_stats_table_read()
820 "rate=0x%X flush time %d\n", lq_sta->tx_packets, in il3945_sta_dbgfs_stats_table_read()
821 lq_sta->last_txrate_idx, lq_sta->start_rate, in il3945_sta_dbgfs_stats_table_read()
822 jiffies_to_msecs(lq_sta->flush_time)); in il3945_sta_dbgfs_stats_table_read()
826 lq_sta->win[j].counter, in il3945_sta_dbgfs_stats_table_read()
827 lq_sta->win[j].success_counter, in il3945_sta_dbgfs_stats_table_read()
828 lq_sta->win[j].success_ratio); in il3945_sta_dbgfs_stats_table_read()
852 * Initialization of rate scaling information is done by driver after
881 struct il_priv *il = hw->priv; in il3945_rate_scale_init()
892 sta = ieee80211_find_sta(il->vif, il->stations[sta_id].sta.sta.addr); in il3945_rate_scale_init()
899 psta = (void *)sta->drv_priv; in il3945_rate_scale_init()
900 rs_sta = &psta->rs_sta; in il3945_rate_scale_init()
902 spin_lock_irqsave(&rs_sta->lock, flags); in il3945_rate_scale_init()
904 rs_sta->tgg = 0; in il3945_rate_scale_init()
905 switch (il->band) { in il3945_rate_scale_init()
908 if (il->active.flags & RXON_FLG_TGG_PROTECT_MSK) { in il3945_rate_scale_init()
909 rs_sta->tgg = 1; in il3945_rate_scale_init()
910 rs_sta->expected_tpt = il3945_expected_tpt_g_prot; in il3945_rate_scale_init()
912 rs_sta->expected_tpt = il3945_expected_tpt_g; in il3945_rate_scale_init()
915 rs_sta->expected_tpt = il3945_expected_tpt_a; in il3945_rate_scale_init()
922 spin_unlock_irqrestore(&rs_sta->lock, flags); in il3945_rate_scale_init()
924 rssi = il->_3945.last_rx_rssi; in il3945_rate_scale_init()
930 rs_sta->start_rate = il3945_get_rate_idx_by_rssi(rssi, il->band); in il3945_rate_scale_init()
933 rs_sta->start_rate, il3945_rates[rs_sta->start_rate].plcp); in il3945_rate_scale_init()