#define IWL_RATE_MAX_WINDOW 62 /* # tx in history window */
/* Calculations of success ratio are done in fixed point where 12800 is 100%. * Use this macro when dealing with thresholds consts set as a percentage
*/ #define RS_PERCENT(x) (128 * x)
staticinline u8 rs_extract_rate(u32 rate_n_flags)
{ /* also works for HT because bits 7:6 are zero there */ return (u8)(rate_n_flags & RATE_LEGACY_RATE_MSK_V1);
}
staticint iwl_hwrate_to_plcp_idx(u32 rate_n_flags)
{ int idx = 0;
/* skip 9M not supported in VHT*/ if (idx >= IWL_RATE_9M_INDEX)
idx++; if ((idx >= IWL_FIRST_VHT_RATE) && (idx <= IWL_LAST_VHT_RATE)) return idx; if ((rate_n_flags & RATE_MCS_HE_MSK_V1) &&
idx <= IWL_LAST_HE_RATE) return idx;
} else { /* legacy rate format, search for match in table */
u8 legacy_rate = rs_extract_rate(rate_n_flags); for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++) if (iwl_rates[idx].plcp == legacy_rate) return idx;
}
/* * The following tables contain the expected throughput metrics for all rates * * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits * * where invalid entries are zeros. * * CCK rates are only valid in legacy table and will only be used in G * (2.4 GHz) band.
*/ staticconst u16 expected_tpt_legacy[IWL_RATE_COUNT] = {
7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 0, 0, 0
};
/* start BA session until the peer sends del BA */
ret = ieee80211_start_tx_ba_session(sta, tid, 0); if (ret == -EAGAIN) { /* * driver and mac80211 is out of sync * this might be cause by reloading firmware * stop the tx ba session here
*/
IWL_ERR(mvm, "Fail start Tx agg on tid: %d\n",
tid);
ieee80211_stop_tx_ba_session(sta, tid);
} return ret;
}
/* * In AP mode, tid can be equal to IWL_MAX_TID_COUNT * when the frame is not QoS
*/ if (WARN_ON_ONCE(tid > IWL_MAX_TID_COUNT)) {
IWL_ERR(mvm, "tid exceeds max TID count: %d/%d\n",
tid, IWL_MAX_TID_COUNT); return;
} elseif (tid == IWL_MAX_TID_COUNT) { return;
}
tid_data = &mvmsta->tid_data[tid]; if (mvmsta->sta_state >= IEEE80211_STA_AUTHORIZED &&
tid_data->state == IWL_AGG_OFF &&
(lq_sta->tx_agg_tid_en & BIT(tid)) &&
tid_data->tx_count_last >= IWL_MVM_RS_AGG_START_THRESHOLD) {
IWL_DEBUG_RATE(mvm, "try to aggregate tid %d\n", tid); if (rs_tl_turn_on_agg_for_tid(mvm, lq_sta, tid, sta) == 0)
tid_data->state = IWL_AGG_QUEUED;
}
}
/* * Static function to get the expected throughput from an iwl_scale_tbl_info * that wraps a NULL pointer check
*/ static s32 get_expected_tpt(struct iwl_scale_tbl_info *tbl, int rs_index)
{ if (tbl->expected_tpt) return tbl->expected_tpt[rs_index]; return 0;
}
/* * rs_collect_tx_data - Update the success/failure sliding window * * We keep a sliding window of the last 62 packets transmitted * at this rate. window->data contains the bitmask of successful * packets.
*/ staticint _rs_collect_tx_data(struct iwl_mvm *mvm, struct iwl_scale_tbl_info *tbl, int scale_index, int attempts, int successes, struct iwl_rate_scale_data *window)
{ staticconst u64 mask = (((u64)1) << (IWL_RATE_MAX_WINDOW - 1));
s32 fail_count, tpt;
/* Get expected throughput */
tpt = get_expected_tpt(tbl, scale_index);
/* * Keep track of only the latest 62 tx frame attempts in this rate's * history window; anything older isn't really relevant any more. * If we have filled up the sliding window, drop the oldest attempt; * if the oldest attempt (highest bit in bitmap) shows "success", * subtract "1" from the success counter (this is the main reason * we keep these bitmaps!).
*/ while (attempts > 0) { if (window->counter >= IWL_RATE_MAX_WINDOW) { /* remove earliest */
window->counter = IWL_RATE_MAX_WINDOW - 1;
/* * Measure if there're enough successful transmits per second. * These statistics are used only to decide if we can start a * BA session, so it should be updated only when A-MPDU is * off.
*/ if (tid_data->state != IWL_AGG_OFF) return;
if (is_legacy(rate)) {
ucode_rate |= iwl_rates[index].plcp; if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
ucode_rate |= RATE_MCS_CCK_MSK_V1; return ucode_rate;
}
/* set RTS protection for all non legacy rates * This helps with congested environments reducing the conflict cost to * RTS retries only, instead of the entire BA packet.
*/
ucode_rate |= RATE_MCS_RTS_REQUIRED_MSK;
if (is_ht(rate)) { if (index < IWL_FIRST_HT_RATE || index > IWL_LAST_HT_RATE) {
IWL_ERR(mvm, "Invalid HT rate index %d\n", index);
index = IWL_LAST_HT_RATE;
}
ucode_rate |= RATE_MCS_HT_MSK_V1;
if (is_ht_siso(rate))
ucode_rate |= iwl_rates[index].plcp_ht_siso; elseif (is_ht_mimo2(rate))
ucode_rate |= iwl_rates[index].plcp_ht_mimo2; else
WARN_ON_ONCE(1);
} elseif (is_vht(rate)) { if (index < IWL_FIRST_VHT_RATE || index > IWL_LAST_VHT_RATE) {
IWL_ERR(mvm, "Invalid VHT rate index %d\n", index);
index = IWL_LAST_VHT_RATE;
}
ucode_rate |= RATE_MCS_VHT_MSK_V1; if (is_vht_siso(rate))
ucode_rate |= iwl_rates[index].plcp_vht_siso; elseif (is_vht_mimo2(rate))
ucode_rate |= iwl_rates[index].plcp_vht_mimo2; else
WARN_ON_ONCE(1);
if (is_siso(rate) && rate->stbc) { /* To enable STBC we need to set both a flag and ANT_AB */
ucode_rate |= RATE_MCS_ANT_AB_MSK;
ucode_rate |= RATE_MCS_STBC_MSK;
}
ucode_rate |= rate->bw; if (rate->sgi)
ucode_rate |= RATE_MCS_SGI_MSK_V1; if (rate->ldpc)
ucode_rate |= RATE_MCS_LDPC_MSK_V1;
/* switch to another antenna/antennas and return 1 */ /* if no other valid antenna found, return 0 */ staticint rs_toggle_antenna(u32 valid_ant, struct rs_rate *rate)
{
u8 new_ant_type;
if (!rs_is_valid_ant(valid_ant, rate->ant)) return 0;
new_ant_type = ant_toggle_lookup[rate->ant];
while ((new_ant_type != rate->ant) &&
!rs_is_valid_ant(valid_ant, new_ant_type))
new_ant_type = ant_toggle_lookup[new_ant_type];
static u16 rs_get_adjacent_rate(struct iwl_mvm *mvm, u8 index, u16 rate_mask, int rate_type)
{
u8 high = IWL_RATE_INVALID;
u8 low = IWL_RATE_INVALID;
/* 802.11A or ht walks to the next literal adjacent rate in
* the rate table */ if (is_type_a_band(rate_type) || !is_type_legacy(rate_type)) { int i;
u32 mask;
/* Find the previous rate that is in the rate mask */
i = index - 1; if (i >= 0)
mask = BIT(i); for (; i >= 0; i--, mask >>= 1) { if (rate_mask & mask) {
low = i; break;
}
}
/* Find the next rate that is in the rate mask */
i = index + 1; for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) { if (rate_mask & mask) {
high = i; break;
}
}
return (high << 8) | low;
}
low = index; while (low != IWL_RATE_INVALID) {
low = iwl_rates[low].prev_rs; if (low == IWL_RATE_INVALID) break; if (rate_mask & (1 << low)) break;
}
high = index; while (high != IWL_RATE_INVALID) {
high = iwl_rates[high].next_rs; if (high == IWL_RATE_INVALID) break; if (rate_mask & (1 << high)) break;
}
/* Get the next supported lower rate in the current column. * Return true if bottom rate in the current column was reached
*/ staticbool rs_get_lower_rate_in_column(struct iwl_lq_sta *lq_sta, struct rs_rate *rate)
{
u8 low;
u16 high_low;
u16 rate_mask; struct iwl_mvm *mvm = lq_sta->pers.drv;
/* Bottom rate of column reached */ if (low == IWL_RATE_INVALID) returntrue;
rate->index = low; returnfalse;
}
/* Get the next rate to use following a column downgrade */ staticvoid rs_get_lower_rate_down_column(struct iwl_lq_sta *lq_sta, struct rs_rate *rate)
{ struct iwl_mvm *mvm = lq_sta->pers.drv;
if (is_legacy(rate)) { /* No column to downgrade from Legacy */ return;
} elseif (is_siso(rate)) { /* Downgrade to Legacy if we were in SISO */ if (lq_sta->band == NL80211_BAND_5GHZ)
rate->type = LQ_LEGACY_A; else
rate->type = LQ_LEGACY_G;
/* * Begin a period of staying with a selected modulation mode. * Set "stay_in_tbl" flag to prevent any mode switches. * Set frame tx success limits according to legacy vs. high-throughput, * and reset overall (spanning all rates) tx success history statistics. * These control how long we stay using same modulation mode before * searching for a new mode.
*/ staticvoid rs_set_stay_in_table(struct iwl_mvm *mvm, u8 is_legacy, struct iwl_lq_sta *lq_sta)
{
IWL_DEBUG_RATE(mvm, "Moving to RS_STATE_STAY_IN_COLUMN\n");
lq_sta->rs_state = RS_STATE_STAY_IN_COLUMN; if (is_legacy) {
lq_sta->table_count_limit = IWL_MVM_RS_LEGACY_TABLE_COUNT;
lq_sta->max_failure_limit = IWL_MVM_RS_LEGACY_FAILURE_LIMIT;
lq_sta->max_success_limit = IWL_MVM_RS_LEGACY_SUCCESS_LIMIT;
} else {
lq_sta->table_count_limit = IWL_MVM_RS_NON_LEGACY_TABLE_COUNT;
lq_sta->max_failure_limit = IWL_MVM_RS_NON_LEGACY_FAILURE_LIMIT;
lq_sta->max_success_limit = IWL_MVM_RS_NON_LEGACY_SUCCESS_LIMIT;
}
lq_sta->table_count = 0;
lq_sta->total_failed = 0;
lq_sta->total_success = 0;
lq_sta->flush_timer = jiffies;
lq_sta->visited_columns = 0;
}
/* rs uses two tables, one is active and the second is for searching better * configuration. This function, according to the index of the currently * active table returns the search table, which is located at the * index complementary to 1 according to the active table (active = 1, * search = 0 or active = 0, search = 1). * Since lq_info is an arary of size 2, make sure index cannot be out of bounds.
*/ staticinline u8 rs_search_tbl(u8 active_tbl)
{ return (active_tbl ^ 1) & 1;
}
switch (sta->deflink.bandwidth) { case IEEE80211_STA_RX_BW_160: /* * Don't use 160 MHz if VHT extended NSS support * says we cannot use 2 streams, we don't want to * deal with this. * We only check MCS 0 - they will support that if * we got here at all and we don't care which MCS, * we want to determine a more global state.
*/ if (ieee80211_get_vht_max_nss(&vht_cap,
IEEE80211_VHT_CHANWIDTH_160MHZ,
0, true,
sta->deflink.rx_nss) < sta->deflink.rx_nss) return RATE_MCS_CHAN_WIDTH_80; return RATE_MCS_CHAN_WIDTH_160; case IEEE80211_STA_RX_BW_80: return RATE_MCS_CHAN_WIDTH_80; case IEEE80211_STA_RX_BW_40: return RATE_MCS_CHAN_WIDTH_40; case IEEE80211_STA_RX_BW_20: default: return RATE_MCS_CHAN_WIDTH_20;
}
}
/* * Check whether we should continue using same modulation mode, or * begin search for a new mode, based on: * 1) # tx successes or failures while using this mode * 2) # times calling this function * 3) elapsed time in this mode (not used, for now)
*/ staticvoid rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search)
{ struct iwl_scale_tbl_info *tbl; int active_tbl; int flush_interval_passed = 0; struct iwl_mvm *mvm;
/* If we've been disallowing search, see if we should now allow it */ if (lq_sta->rs_state == RS_STATE_STAY_IN_COLUMN) { /* Elapsed time using current modulation mode */ if (lq_sta->flush_timer)
flush_interval_passed =
time_after(jiffies,
(unsignedlong)(lq_sta->flush_timer +
(IWL_MVM_RS_STAY_IN_COLUMN_TIMEOUT * HZ)));
/* * Check if we should allow search for new modulation mode. * If many frames have failed or succeeded, or we've used * this same modulation for a long time, allow search, and * reset history stats that keep track of whether we should * allow a new search. Also (below) reset all bitmaps and * stats in active history.
*/ if (force_search ||
(lq_sta->total_failed > lq_sta->max_failure_limit) ||
(lq_sta->total_success > lq_sta->max_success_limit) ||
((!lq_sta->search_better_tbl) &&
(lq_sta->flush_timer) && (flush_interval_passed))) {
IWL_DEBUG_RATE(mvm, "LQ: stay is expired %d %d %d\n",
lq_sta->total_failed,
lq_sta->total_success,
flush_interval_passed);
/* Allow search for new mode */
lq_sta->rs_state = RS_STATE_SEARCH_CYCLE_STARTED;
IWL_DEBUG_RATE(mvm, "Moving to RS_STATE_SEARCH_CYCLE_STARTED\n");
lq_sta->total_failed = 0;
lq_sta->total_success = 0;
lq_sta->flush_timer = 0; /* mark the current column as visited */
lq_sta->visited_columns = BIT(tbl->column); /* * Else if we've used this modulation mode enough repetitions * (regardless of elapsed time or success/failure), reset * history bitmaps and rate-specific stats for all rates in * active table.
*/
} else {
lq_sta->table_count++; if (lq_sta->table_count >=
lq_sta->table_count_limit) {
lq_sta->table_count = 0;
/* If transitioning to allow "search", reset all history * bitmaps and stats in active table (this will become the new
* "search" table). */ if (lq_sta->rs_state == RS_STATE_SEARCH_CYCLE_STARTED) {
rs_rate_scale_clear_tbl_windows(mvm, tbl);
}
}
}
/* * In case TLC offload is not active amsdu_enabled is either 0xFFFF * or 0, since there is no per-TID alg.
*/ if ((!is_vht(&tbl->rate) && !is_ht(&tbl->rate)) ||
tbl->rate.index < IWL_RATE_MCS_5_INDEX ||
scale_action == RS_ACTION_DOWNSCALE)
mvmsta->amsdu_enabled = 0; else
mvmsta->amsdu_enabled = 0xFFFF;
for (i = 0; i < IWL_MAX_TID_COUNT; i++) { if (mvmsta->amsdu_enabled)
sta->deflink.agg.max_tid_amsdu_len[i] =
iwl_mvm_max_amsdu_size(mvm, sta, i); else /* * Not so elegant, but this will effectively * prevent AMSDU on this TID
*/
sta->deflink.agg.max_tid_amsdu_len[i] = 1;
}
}
/* Go back to 80Mhz MCS1 only if we've established that 20Mhz MCS5 is * sustainable, i.e. we're past the test window. We can't go back * if MCS5 is just tested as this will happen always after switching * to 20Mhz MCS4 because the rate stats are cleared.
*/ if ((tbl->rate.bw == RATE_MCS_CHAN_WIDTH_20) &&
(((tbl->rate.index == IWL_RATE_MCS_5_INDEX) &&
(scale_action == RS_ACTION_STAY)) ||
((tbl->rate.index > IWL_RATE_MCS_5_INDEX) &&
(scale_action == RS_ACTION_UPSCALE)))) {
tbl->rate.bw = RATE_MCS_CHAN_WIDTH_80;
tbl->rate.index = IWL_RATE_MCS_1_INDEX;
IWL_DEBUG_RATE(mvm, "Switch 20Mhz SISO MCS5 -> 80Mhz MCS1\n"); goto tweaked;
}
if (!rs_is_valid_ant(valid_ants, next_col->ant)) {
IWL_DEBUG_RATE(mvm, "Skip column %d as ANT config isn't supported by chip. valid_ants 0x%x column ant 0x%x\n",
next_col_id, valid_ants, next_col->ant); continue;
}
max_rate = rs_get_max_allowed_rate(lq_sta, next_col); if (max_rate == IWL_RATE_INVALID) {
IWL_DEBUG_RATE(mvm, "Skip column %d: no rate is allowed in this column\n",
next_col_id); continue;
}
max_expected_tpt = expected_tpt_tbl[max_rate]; if (tpt >= max_expected_tpt) {
IWL_DEBUG_RATE(mvm, "Skip column %d: can't beat current TPT. Max expected %d current %d\n",
next_col_id, max_expected_tpt, tpt); continue;
}
IWL_DEBUG_RATE(mvm, "Found potential column %d. Max expected %d current %d\n",
next_col_id, max_expected_tpt, tpt); break;
}
if (i == MAX_NEXT_COLUMNS) return RS_COLUMN_INVALID;
/* Get the best matching rate if we're changing modes. e.g. * SISO->MIMO, LEGACY->SISO, MIMO->SISO
*/ if (curr_column->mode != column->mode) {
rate_idx = rs_get_best_rate(mvm, lq_sta, search_tbl,
rate_mask, rate->index);
if ((rate_idx == IWL_RATE_INVALID) ||
!(BIT(rate_idx) & rate_mask)) {
IWL_DEBUG_RATE(mvm, "can not switch with index %d" " rate mask %lx\n",
rate_idx, rate_mask);
goto err;
}
rate->index = rate_idx;
}
IWL_DEBUG_RATE(mvm, "Switched to column %d: Index %d\n",
col_id, rate->index);
return 0;
err:
rate->type = LQ_NONE; return -1;
}
staticenum rs_action rs_get_rate_action(struct iwl_mvm *mvm, struct iwl_scale_tbl_info *tbl,
s32 sr, int low, int high, int current_tpt, int low_tpt, int high_tpt)
{ enum rs_action action = RS_ACTION_STAY;
if ((sr <= RS_PERCENT(IWL_MVM_RS_SR_FORCE_DECREASE)) ||
(current_tpt == 0)) {
IWL_DEBUG_RATE(mvm, "Decrease rate because of low SR\n"); return RS_ACTION_DOWNSCALE;
}
if ((low_tpt == IWL_INVALID_VALUE) &&
(high_tpt == IWL_INVALID_VALUE) &&
(high != IWL_RATE_INVALID)) {
IWL_DEBUG_RATE(mvm, "No data about high/low rates. Increase rate\n"); return RS_ACTION_UPSCALE;
}
if ((high_tpt == IWL_INVALID_VALUE) &&
(high != IWL_RATE_INVALID) &&
(low_tpt != IWL_INVALID_VALUE) &&
(low_tpt < current_tpt)) {
IWL_DEBUG_RATE(mvm, "No data about high rate and low rate is worse. Increase rate\n"); return RS_ACTION_UPSCALE;
}
if ((high_tpt != IWL_INVALID_VALUE) &&
(high_tpt > current_tpt)) {
IWL_DEBUG_RATE(mvm, "Higher rate is better. Increase rate\n"); return RS_ACTION_UPSCALE;
}
if ((low_tpt != IWL_INVALID_VALUE) &&
(high_tpt != IWL_INVALID_VALUE) &&
(low_tpt < current_tpt) &&
(high_tpt < current_tpt)) {
IWL_DEBUG_RATE(mvm, "Both high and low are worse. Maintain rate\n"); return RS_ACTION_STAY;
}
if ((low_tpt != IWL_INVALID_VALUE) &&
(low_tpt > current_tpt)) {
IWL_DEBUG_RATE(mvm, "Lower rate is better\n");
action = RS_ACTION_DOWNSCALE; goto out;
}
if ((low_tpt == IWL_INVALID_VALUE) &&
(low != IWL_RATE_INVALID)) {
IWL_DEBUG_RATE(mvm, "No data about lower rate\n");
action = RS_ACTION_DOWNSCALE; goto out;
}
IWL_DEBUG_RATE(mvm, "Maintain rate\n");
out: if ((action == RS_ACTION_DOWNSCALE) && (low != IWL_RATE_INVALID)) { if (sr >= RS_PERCENT(IWL_MVM_RS_SR_NO_DECREASE)) {
IWL_DEBUG_RATE(mvm, "SR is above NO DECREASE. Avoid downscale\n");
action = RS_ACTION_STAY;
} elseif (current_tpt > (100 * tbl->expected_tpt[low])) {
IWL_DEBUG_RATE(mvm, "Current TPT is higher than max expected in low rate. Avoid downscale\n");
action = RS_ACTION_STAY;
} else {
IWL_DEBUG_RATE(mvm, "Decrease rate\n");
}
}
return action;
}
staticbool rs_stbc_allow(struct iwl_mvm *mvm, struct ieee80211_sta *sta, struct iwl_lq_sta *lq_sta)
{ /* Our chip supports Tx STBC and the peer is an HT/VHT STA which * supports STBC of at least 1*SS
*/ if (!lq_sta->stbc_capable) returnfalse;
if (!iwl_mvm_bt_coex_is_mimo_allowed(mvm, sta)) returnfalse;
returntrue;
}
staticvoid rs_get_adjacent_txp(struct iwl_mvm *mvm, int index, int *weaker, int *stronger)
{
*weaker = index + IWL_MVM_RS_TPC_TX_POWER_STEP; if (*weaker > TPC_MAX_REDUCTION)
*weaker = TPC_INVALID;
*stronger = index - IWL_MVM_RS_TPC_TX_POWER_STEP; if (*stronger < 0)
*stronger = TPC_INVALID;
}
IWL_DEBUG_RATE(mvm, "cam: %d sta_ps_disabled %d\n",
cam, sta_ps_disabled); /* * allow tpc only if power management is enabled, or bt coex * activity grade allows it and we are on 2.4Ghz.
*/ if ((cam || sta_ps_disabled) &&
!iwl_mvm_bt_coex_is_tpc_allowed(mvm, band)) returnfalse;
IWL_DEBUG_RATE(mvm, "check rate, table type: %d\n", rate->type); if (is_legacy(rate)) return index == IWL_RATE_54M_INDEX; if (is_ht(rate)) return index == IWL_RATE_MCS_7_INDEX; if (is_vht(rate)) return index == IWL_RATE_MCS_9_INDEX;
staticenum tpc_action rs_get_tpc_action(struct iwl_mvm *mvm,
s32 sr, int weak, int strong, int current_tpt, int weak_tpt, int strong_tpt)
{ /* stay until we have valid tpt */ if (current_tpt == IWL_INVALID_VALUE) {
IWL_DEBUG_RATE(mvm, "no current tpt. stay.\n"); return TPC_ACTION_STAY;
}
/* Too many failures, increase txp */ if (sr <= RS_PERCENT(IWL_MVM_RS_TPC_SR_FORCE_INCREASE) ||
current_tpt == 0) {
IWL_DEBUG_RATE(mvm, "increase txp because of weak SR\n"); return TPC_ACTION_NO_RESTIRCTION;
}
/* try decreasing first if applicable */ if (sr >= RS_PERCENT(IWL_MVM_RS_TPC_SR_NO_INCREASE) &&
weak != TPC_INVALID) { if (weak_tpt == IWL_INVALID_VALUE &&
(strong_tpt == IWL_INVALID_VALUE ||
current_tpt >= strong_tpt)) {
IWL_DEBUG_RATE(mvm, "no weak txp measurement. decrease txp\n"); return TPC_ACTION_DECREASE;
}
if (weak_tpt > current_tpt) {
IWL_DEBUG_RATE(mvm, "lower txp has better tpt. decrease txp\n"); return TPC_ACTION_DECREASE;
}
}
/* next, increase if needed */ if (sr < RS_PERCENT(IWL_MVM_RS_TPC_SR_NO_INCREASE) &&
strong != TPC_INVALID) { if (weak_tpt == IWL_INVALID_VALUE &&
strong_tpt != IWL_INVALID_VALUE &&
current_tpt < strong_tpt) {
IWL_DEBUG_RATE(mvm, "higher txp has better tpt. increase txp\n"); return TPC_ACTION_INCREASE;
}
rcu_read_lock();
chanctx_conf = rcu_dereference(vif->bss_conf.chanctx_conf); if (WARN_ON(!chanctx_conf))
band = NUM_NL80211_BANDS; else
band = chanctx_conf->def.chan->band;
rcu_read_unlock();
if (!rs_tpc_allowed(mvm, vif, rate, band)) {
IWL_DEBUG_RATE(mvm, "tpc is not allowed. remove txp restrictions\n");
lq_sta->lq.reduced_tpc = TPC_NO_REDUCTION; return cur != TPC_NO_REDUCTION;
}
rs_get_adjacent_txp(mvm, cur, &weak, &strong);
/* Collect measured throughputs for current and adjacent rates */
window = tbl->tpc_win;
sr = window[cur].success_ratio;
current_tpt = window[cur].average_tpt; if (weak != TPC_INVALID)
weak_tpt = window[weak].average_tpt; if (strong != TPC_INVALID)
strong_tpt = window[strong].average_tpt;
/* override actions if we are on the edge */ if (weak == TPC_INVALID && action == TPC_ACTION_DECREASE) {
IWL_DEBUG_RATE(mvm, "already in lowest txp, stay\n");
action = TPC_ACTION_STAY;
} elseif (strong == TPC_INVALID &&
(action == TPC_ACTION_INCREASE ||
action == TPC_ACTION_NO_RESTIRCTION)) {
IWL_DEBUG_RATE(mvm, "already in highest txp, stay\n");
action = TPC_ACTION_STAY;
}
switch (action) { case TPC_ACTION_DECREASE:
lq_sta->lq.reduced_tpc = weak; returntrue; case TPC_ACTION_INCREASE:
lq_sta->lq.reduced_tpc = strong; returntrue; case TPC_ACTION_NO_RESTIRCTION:
lq_sta->lq.reduced_tpc = TPC_NO_REDUCTION; returntrue; case TPC_ACTION_STAY: /* do nothing */ break;
} returnfalse;
}
/* * Do rate scaling and search for new modulation mode.
*/ staticvoid rs_rate_scale_perform(struct iwl_mvm *mvm, struct ieee80211_sta *sta, struct iwl_lq_sta *lq_sta, int tid, bool ndp)
{ int low = IWL_RATE_INVALID; int high = IWL_RATE_INVALID; int index; struct iwl_rate_scale_data *window = NULL; int current_tpt = IWL_INVALID_VALUE; int low_tpt = IWL_INVALID_VALUE; int high_tpt = IWL_INVALID_VALUE;
u32 fail_count; enum rs_action scale_action = RS_ACTION_STAY;
u16 rate_mask;
u8 update_lq = 0; struct iwl_scale_tbl_info *tbl, *tbl1;
u8 active_tbl = 0;
u8 done_search = 0;
u16 high_low;
s32 sr;
u8 prev_agg = lq_sta->is_agg; struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); struct rs_rate *rate;
lq_sta->is_agg = !!mvmsta->agg_tids;
/* * Select rate-scale / modulation-mode table to work with in * the rest of this function: "search" if searching for better * modulation mode, or "active" if doing rate scaling within a mode.
*/ if (!lq_sta->search_better_tbl)
active_tbl = lq_sta->active_tbl; else
active_tbl = rs_search_tbl(lq_sta->active_tbl);
/* rates available for this association, and for modulation mode */
rate_mask = rs_get_supported_rates(lq_sta, rate);
if (!(BIT(index) & rate_mask)) {
IWL_ERR(mvm, "Current Rate is not valid\n"); if (lq_sta->search_better_tbl) { /* revert to active table if search table is not valid*/
rate->type = LQ_NONE;
lq_sta->search_better_tbl = 0;
tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
rs_update_rate_tbl(mvm, sta, lq_sta, tbl);
} return;
}
/* Get expected throughput table and history window for current rate */ if (!tbl->expected_tpt) {
IWL_ERR(mvm, "tbl->expected_tpt is NULL\n"); return;
}
/* TODO: handle rate_idx_mask and rate_idx_mcs_mask */
window = &(tbl->win[index]);
/* * If there is not enough history to calculate actual average * throughput, keep analyzing results of more tx frames, without * changing rate or mode (bypass most of the rest of this function). * Set up new rate table in uCode only if old rate is not supported * in current association (use new rate found above).
*/
fail_count = window->counter - window->success_counter; if ((fail_count < IWL_MVM_RS_RATE_MIN_FAILURE_TH) &&
(window->success_counter < IWL_MVM_RS_RATE_MIN_SUCCESS_TH)) {
IWL_DEBUG_RATE(mvm, "%s: Test Window: succ %d total %d\n",
rs_pretty_rate(rate),
window->success_counter, window->counter);
/* Can't calculate this yet; not enough history */
window->average_tpt = IWL_INVALID_VALUE;
/* Should we stay with this modulation mode,
* or search for a new one? */
rs_stay_in_table(lq_sta, false);
return;
}
/* If we are searching for better modulation mode, check success. */ if (lq_sta->search_better_tbl) { /* If good success, continue using the "search" mode; * no need to send new link quality command, since we're
* continuing to use the setup that we've been trying. */ if (window->average_tpt > lq_sta->last_tpt) {
IWL_DEBUG_RATE(mvm, "SWITCHING TO NEW TABLE SR: %d " "cur-tpt %d old-tpt %d\n",
window->success_ratio,
window->average_tpt,
lq_sta->last_tpt);
/* Swap tables; "search" becomes "active" */
lq_sta->active_tbl = active_tbl;
current_tpt = window->average_tpt; /* Else poor success; go back to mode in "active" table */
} else {
IWL_DEBUG_RATE(mvm, "GOING BACK TO THE OLD TABLE: SR %d " "cur-tpt %d old-tpt %d\n",
window->success_ratio,
window->average_tpt,
lq_sta->last_tpt);
/* Revert to "active" rate and throughput info */
index = tbl->rate.index;
current_tpt = lq_sta->last_tpt;
/* Need to set up a new rate table in uCode */
update_lq = 1;
}
/* Either way, we've made a decision; modulation mode
* search is done, allow rate adjustment next time. */
lq_sta->search_better_tbl = 0;
done_search = 1; /* Don't switch modes below! */ goto lq_update;
}
/* (Else) not in search of better modulation mode, try for better
* starting rate, while staying in this mode. */
high_low = rs_get_adjacent_rate(mvm, index, rate_mask, rate->type);
low = high_low & 0xff;
high = (high_low >> 8) & 0xff;
/* TODO: handle rate_idx_mask and rate_idx_mcs_mask */
sr = window->success_ratio;
/* Collect measured throughputs for current and adjacent rates */
current_tpt = window->average_tpt; if (low != IWL_RATE_INVALID)
low_tpt = tbl->win[low].average_tpt; if (high != IWL_RATE_INVALID)
high_tpt = tbl->win[high].average_tpt;
/* Force a search in case BT doesn't like us being in MIMO */ if (is_mimo(rate) &&
!iwl_mvm_bt_coex_is_mimo_allowed(mvm, sta)) {
IWL_DEBUG_RATE(mvm, "BT Coex forbids MIMO. Search for new config\n");
rs_stay_in_table(lq_sta, true); goto lq_update;
}
switch (scale_action) { case RS_ACTION_DOWNSCALE: /* Decrease starting rate, update uCode's rate table */ if (low != IWL_RATE_INVALID) {
update_lq = 1;
index = low;
} else {
IWL_DEBUG_RATE(mvm, "At the bottom rate. Can't decrease\n");
}
break; case RS_ACTION_UPSCALE: /* Increase starting rate, update uCode's rate table */ if (high != IWL_RATE_INVALID) {
update_lq = 1;
index = high;
} else {
IWL_DEBUG_RATE(mvm, "At the top rate. Can't increase\n");
}
break; case RS_ACTION_STAY: /* No change */ if (lq_sta->rs_state == RS_STATE_STAY_IN_COLUMN)
update_lq = rs_tpc_perform(mvm, sta, lq_sta, tbl); break; default: break;
}
lq_update: /* Replace uCode's rate table for the destination station. */ if (update_lq) {
tbl->rate.index = index; if (IWL_MVM_RS_80_20_FAR_RANGE_TWEAK)
rs_tweak_rate_tbl(mvm, sta, lq_sta, tbl, scale_action);
rs_set_amsdu_len(mvm, sta, tbl, scale_action);
rs_update_rate_tbl(mvm, sta, lq_sta, tbl);
}
rs_stay_in_table(lq_sta, false);
/* * Search for new modulation mode if we're: * 1) Not changing rates right now * 2) Not just finishing up a search * 3) Allowing a new search
*/ if (!update_lq && !done_search &&
lq_sta->rs_state == RS_STATE_SEARCH_CYCLE_STARTED
&& window->counter) { enum rs_column next_column;
/* Save current throughput to compare with "search" throughput*/
lq_sta->last_tpt = current_tpt;
next_column = rs_get_next_column(mvm, lq_sta, sta, tbl); if (next_column != RS_COLUMN_INVALID) { int ret = rs_switch_to_column(mvm, lq_sta, sta,
next_column); if (!ret)
lq_sta->search_better_tbl = 1;
} else {
IWL_DEBUG_RATE(mvm, "No more columns to explore in search cycle. Go to RS_STATE_SEARCH_CYCLE_ENDED\n");
lq_sta->rs_state = RS_STATE_SEARCH_CYCLE_ENDED;
}
/* If new "search" mode was selected, set up in uCode table */ if (lq_sta->search_better_tbl) { /* Access the "search" table, clear its history. */
tbl = &lq_sta->lq_info[rs_search_tbl(lq_sta->active_tbl)];
--> --------------------
--> maximum size reached
--> --------------------
Messung V0.5
¤ Dauer der Verarbeitung: 0.27 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.