#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)];
rs_rate_scale_clear_tbl_windows(mvm, tbl);
/* Use new "search" start rate */
index = tbl->rate.index;
/* Init the optimal rate based on STA caps * This combined with rssi is used to report the last tx rate * to userspace when we haven't transmitted enough frames.
*/ staticvoid rs_init_optimal_rate(struct iwl_mvm *mvm, struct ieee80211_sta *sta, struct iwl_lq_sta *lq_sta)
{ struct rs_rate *rate = &lq_sta->optimal_rate;
/* Start from a higher rate if the corresponding debug capability * is enabled. The rate is chosen according to AP capabilities. * In case of VHT/HT when the rssi is low fallback to the case of * legacy rates.
*/ if (sta->deflink.vht_cap.vht_supported &&
best_rssi > IWL_RS_LOW_RSSI_THRESHOLD) { /* * In AP mode, when a new station associates, rs is initialized * immediately upon association completion, before the phy * context is updated with the association parameters, so the * sta bandwidth might be wider than the phy context allows. * To avoid this issue, always initialize rs with 20mhz * bandwidth rate, and after authorization, when the phy context * is already up-to-date, re-init rs with the correct bw.
*/
u32 bw = mvmsta->sta_state < IEEE80211_STA_AUTHORIZED ?
RATE_MCS_CHAN_WIDTH_20 : rs_bw_from_sta_bw(sta);
switch (bw) { case RATE_MCS_CHAN_WIDTH_40: case RATE_MCS_CHAN_WIDTH_80: case RATE_MCS_CHAN_WIDTH_160:
initial_rates = rs_optimal_rates_vht;
nentries = ARRAY_SIZE(rs_optimal_rates_vht); break; case RATE_MCS_CHAN_WIDTH_20:
initial_rates = rs_optimal_rates_vht_20mhz;
nentries = ARRAY_SIZE(rs_optimal_rates_vht_20mhz); break; default:
IWL_ERR(mvm, "Invalid BW %d\n",
sta->deflink.bandwidth); goto out;
}
/* Save info about RSSI of last Rx */ void rs_update_last_rssi(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, struct ieee80211_rx_status *rx_status)
{ struct iwl_lq_sta *lq_sta = &mvmsta->deflink.lq_sta.rs_drv; int i;
for (i = 0; i < ARRAY_SIZE(lq_sta->pers.chain_signal); i++) { if (!(lq_sta->pers.chains & BIT(i))) continue;
if (lq_sta->pers.chain_signal[i] > lq_sta->pers.last_rssi)
lq_sta->pers.last_rssi = lq_sta->pers.chain_signal[i];
}
}
/* * rs_initialize_lq - Initialize a station's hardware rate table * * The uCode's station table contains a table of fallback rates * for automatic fallback during transmission. * * NOTE: This sets up a default set of values. These will be replaced later * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of * rc80211_simple. * * NOTE: Run REPLY_ADD_STA command to set up station table entry, before * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD, * which requires station table entry to exist).
*/ staticvoid rs_initialize_lq(struct iwl_mvm *mvm, struct ieee80211_sta *sta, struct iwl_lq_sta *lq_sta, enum nl80211_band band)
{ struct iwl_scale_tbl_info *tbl; struct rs_rate *rate;
u8 active_tbl = 0;
if (!sta || !lq_sta) return;
if (!lq_sta->search_better_tbl)
active_tbl = lq_sta->active_tbl; else
active_tbl = rs_search_tbl(lq_sta->active_tbl);
rs_set_expected_tpt_table(lq_sta, tbl);
rs_fill_lq_cmd(mvm, sta, lq_sta, rate); /* TODO restore station should remember the lq cmd */
iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq);
}
if (sta && !iwl_mvm_sta_from_mac80211(sta)->vif) { /* if vif isn't initialized mvm doesn't know about * this station, so don't do anything with the it
*/
mvm_sta = NULL;
}
/* Report the optimal rate based on rssi and STA caps if we haven't * converged yet (too little traffic) or exploring other modulations
*/ if (lq_sta->rs_state != RS_STATE_STAY_IN_COLUMN) {
optimal_rate = rs_get_optimal_rate(mvm, lq_sta);
last_ucode_rate = ucode_rate_from_rs_rate(mvm,
optimal_rate);
last_ucode_rate =
iwl_mvm_v3_rate_from_fw(cpu_to_le32(last_ucode_rate),
1);
iwl_mvm_hwrate_to_tx_rate(last_ucode_rate, info->band,
&txrc->reported_rate);
txrc->reported_rate.count = 1;
}
spin_unlock_bh(&lq_sta->pers.lock);
}
staticvoid rs_vht_set_enabled_rates(struct ieee80211_sta *sta, struct ieee80211_sta_vht_cap *vht_cap, struct iwl_lq_sta *lq_sta)
{ int i; int highest_mcs = rs_vht_highest_rx_mcs_index(vht_cap, 1);
if (highest_mcs >= IWL_RATE_MCS_0_INDEX) { for (i = IWL_RATE_MCS_0_INDEX; i <= highest_mcs; i++) { if (i == IWL_RATE_9M_INDEX) continue;
/* VHT MCS9 isn't valid for 20Mhz for NSS=1,2 */ if (i == IWL_RATE_MCS_9_INDEX &&
sta->deflink.bandwidth == IEEE80211_STA_RX_BW_20) continue;
lq_sta->active_siso_rate |= BIT(i);
}
}
if (sta->deflink.rx_nss < 2) return;
highest_mcs = rs_vht_highest_rx_mcs_index(vht_cap, 2); if (highest_mcs >= IWL_RATE_MCS_0_INDEX) { for (i = IWL_RATE_MCS_0_INDEX; i <= highest_mcs; i++) { if (i == IWL_RATE_9M_INDEX) continue;
/* VHT MCS9 isn't valid for 20Mhz for NSS=1,2 */ if (i == IWL_RATE_MCS_9_INDEX &&
sta->deflink.bandwidth == IEEE80211_STA_RX_BW_20) continue;
lq_sta->active_mimo2_rate |= BIT(i);
}
}
}
staticvoid rs_ht_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta, struct iwl_lq_sta *lq_sta, struct ieee80211_sta_ht_cap *ht_cap)
{ /* active_siso_rate mask includes 9 MBits (bit 5), * and CCK (bits 0-3), supp_rates[] does not; * shift to convert format, force 9 MBits off.
*/
lq_sta->active_siso_rate = ht_cap->mcs.rx_mask[0] << 1;
lq_sta->active_siso_rate |= ht_cap->mcs.rx_mask[0] & 0x1;
lq_sta->active_siso_rate &= ~((u16)0x2);
lq_sta->active_siso_rate <<= IWL_FIRST_OFDM_RATE;
IWL_DEBUG_RATE(mvm, "LQ: *** rate scale station global init for station %d ***\n",
mvmsta->deflink.sta_id); /* TODO: what is a good starting rate for STA? About middle? Maybe not * the lowest or the highest rate.. Could consider using RSSI from * previous packets? Need to have IEEE 802.1X auth succeed immediately
* after assoc.. */
lq_sta->missed_rate_counter = IWL_MVM_RS_MISSED_RATE_MAX;
lq_sta->band = sband->band; /* * active legacy rates as per supported rates bitmap
*/
supp = sta->deflink.supp_rates[sband->band];
lq_sta->active_legacy_rate = 0;
for_each_set_bit(i, &supp, BITS_PER_LONG)
lq_sta->active_legacy_rate |= BIT(sband->bitrates[i].hw_value);
/* TODO: should probably account for rx_highest for both HT/VHT */ if (!vht_cap || !vht_cap->vht_supported)
rs_ht_init(mvm, sta, lq_sta, ht_cap); else
rs_vht_init(mvm, sta, lq_sta, vht_cap);
/* These values will be overridden later */
lq_sta->lq.single_stream_ant_msk =
iwl_mvm_bt_coex_get_single_ant_msk(mvm, iwl_mvm_get_valid_tx_ant(mvm));
lq_sta->lq.dual_stream_ant_msk = ANT_AB;
/* as default allow aggregation for all tids */
lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID;
lq_sta->is_agg = 0; #ifdef CONFIG_IWLWIFI_DEBUGFS
iwl_mvm_reset_frame_stats(mvm); #endif
rs_initialize_lq(mvm, sta, lq_sta, band);
}
/* Stop any ongoing aggregations as rs starts off assuming no agg */ for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++)
ieee80211_stop_tx_ba_session(sta, tid);
if (!lq_sta->pers.drv) {
IWL_DEBUG_RATE(mvm, "Rate scaling not initialized yet.\n"); return;
}
/* This packet was aggregated but doesn't carry status info */ if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
!(info->flags & IEEE80211_TX_STAT_AMPDU)) return;
if (rs_rate_from_ucode_rate(tx_resp_hwrate, info->band,
&tx_resp_rate)) {
WARN_ON_ONCE(1); return;
}
#ifdef CONFIG_MAC80211_DEBUGFS /* Disable last tx check if we are debugging with fixed rate but * update tx stats
*/ if (lq_sta->pers.dbg_fixed_rate) { int index = tx_resp_rate.index; enum rs_column column; int attempts, success;
column = rs_get_column_from_rate(&tx_resp_rate); if (WARN_ONCE(column == RS_COLUMN_INVALID, "Can't map rate 0x%x to column",
tx_resp_hwrate)) return;
if (time_after(jiffies,
(unsignedlong)(lq_sta->last_tx +
(IWL_MVM_RS_IDLE_TIMEOUT * HZ)))) {
IWL_DEBUG_RATE(mvm, "Tx idle for too long. reinit rs\n"); /* reach here only in case of driver RS, call directly * the unlocked version
*/
rs_drv_rate_init(mvm, sta, info->band); return;
}
lq_sta->last_tx = jiffies;
/* Ignore this Tx frame response if its initial rate doesn't match * that of latest Link Quality command. There may be stragglers * from a previous Link Quality command, but we're no longer interested * in those; they're either from the "active" mode while we're trying * to check "search" mode, or a prior "search" mode after we've moved * to a new "search" mode (which might become the new "active" mode).
*/
table = &lq_sta->lq;
lq_hwrate = le32_to_cpu(table->rs_table[0]); if (rs_rate_from_ucode_rate(lq_hwrate, info->band, &lq_rate)) {
WARN_ON_ONCE(1); return;
}
/* Here we actually compare this rate to the latest LQ command */ if (lq_color != LQ_FLAG_COLOR_GET(table->flags)) {
IWL_DEBUG_RATE(mvm, "tx resp color 0x%x does not match 0x%x\n",
lq_color, LQ_FLAG_COLOR_GET(table->flags));
/* Since rates mis-match, the last LQ command may have failed. * After IWL_MISSED_RATE_MAX mis-matches, resync the uCode with * ... driver.
*/
lq_sta->missed_rate_counter++; if (lq_sta->missed_rate_counter > IWL_MVM_RS_MISSED_RATE_MAX) {
lq_sta->missed_rate_counter = 0;
IWL_DEBUG_RATE(mvm, "Too many rates mismatch. Send sync LQ. rs_state %d\n",
lq_sta->rs_state);
iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq);
} /* Regardless, ignore this status info for outdated rate */ return;
}
/* Rate did match, so reset the missed_rate_counter */
lq_sta->missed_rate_counter = 0;
if (WARN_ON_ONCE(!rs_rate_column_match(&lq_rate, &curr_tbl->rate))) {
IWL_DEBUG_RATE(mvm, "Neither active nor search matches tx rate\n");
tmp_tbl = &lq_sta->lq_info[lq_sta->active_tbl];
rs_dump_rate(mvm, &tmp_tbl->rate, "ACTIVE");
tmp_tbl = &lq_sta->lq_info[rs_search_tbl(lq_sta->active_tbl)];
rs_dump_rate(mvm, &tmp_tbl->rate, "SEARCH");
rs_dump_rate(mvm, &lq_rate, "ACTUAL");
/* no matching table found, let's by-pass the data collection * and continue to perform rate scale to find the rate table
*/
rs_stay_in_table(lq_sta, true); goto done;
}
/* Updating the frame history depends on whether packets were * aggregated. * * For aggregation, all packets were transmitted at the same rate, the * first index into rate scale table.
*/ if (info->flags & IEEE80211_TX_STAT_AMPDU) {
rs_collect_tpc_data(mvm, lq_sta, curr_tbl, tx_resp_rate.index,
info->status.ampdu_len,
info->status.ampdu_ack_len,
reduced_txp);
/* ampdu_ack_len = 0 marks no BA was received. For TLC, treat * it as a single frame loss as we don't want the success ratio * to dip too quickly because a BA wasn't received. * For TPC, there's no need for this optimisation since we want * to recover very quickly from a bad power reduction and, * therefore we'd like the success ratio to get an immediate hit * when failing to get a BA, so we'd switch back to a lower or * zero power reduction. When FW transmits agg with a rate * different from the initial rate, it will not use reduced txp * and will send BA notification twice (one empty with reduced * txp equal to the value from LQ and one with reduced txp 0). * We need to update counters for each txp level accordingly.
*/ if (info->status.ampdu_ack_len == 0)
info->status.ampdu_len = 1;
/* Update success/fail counts if not searching for new mode */ if (lq_sta->rs_state == RS_STATE_STAY_IN_COLUMN) {
lq_sta->total_success += info->status.ampdu_ack_len;
lq_sta->total_failed += (info->status.ampdu_len -
info->status.ampdu_ack_len);
}
} else { /* For legacy, update frame history with for each Tx retry. */
retries = info->status.rates[0].count - 1; /* HW doesn't send more than 15 retries */
retries = min(retries, 15);
/* The last transmission may have been successful */
legacy_success = !!(info->flags & IEEE80211_TX_STAT_ACK); /* Collect data for each rate used during failed TX attempts */ for (i = 0; i <= retries; ++i) {
lq_hwrate = le32_to_cpu(table->rs_table[i]); if (rs_rate_from_ucode_rate(lq_hwrate, info->band,
&lq_rate)) {
WARN_ON_ONCE(1); return;
}
/* Only collect stats if retried rate is in the same RS * table as active/search.
*/ if (rs_rate_column_match(&lq_rate, &curr_tbl->rate))
tmp_tbl = curr_tbl; elseif (rs_rate_column_match(&lq_rate,
&other_tbl->rate))
tmp_tbl = other_tbl; else continue;
/* Update success/fail counts if not searching for new mode */ if (lq_sta->rs_state == RS_STATE_STAY_IN_COLUMN) {
lq_sta->total_success += legacy_success;
lq_sta->total_failed += retries + (1 - legacy_success);
}
} /* The last TX rate is cached in lq_sta; it's set in if/else above */
lq_sta->last_rate_n_flags = lq_hwrate;
IWL_DEBUG_RATE(mvm, "reduced txpower: %d\n", reduced_txp);
done: /* See if there's a better rate or modulation mode to try. */ if (sta->deflink.supp_rates[info->band])
rs_rate_scale_perform(mvm, sta, lq_sta, tid, ndp);
}
/* If it's locked we are in middle of init flow * just wait for next tx status to update the lq_sta data
*/ if (!spin_trylock_bh(&mvmsta->deflink.lq_sta.rs_drv.pers.lock)) return;
staticvoid rs_fill_rates_for_column(struct iwl_mvm *mvm, struct iwl_lq_sta *lq_sta, struct rs_rate *rate,
__le32 *rs_table, int *rs_table_index, int num_rates, int num_retries,
u8 valid_tx_ant, bool toggle_ant)
{ int i, j;
__le32 ucode_rate; bool bottom_reached = false; int prev_rate_idx = rate->index; int end = LINK_QUAL_MAX_RETRY_NUM; int index = *rs_table_index;
for (i = 0; i < num_rates && index < end; i++) { for (j = 0; j < num_retries && index < end; j++, index++) {
ucode_rate = cpu_to_le32(ucode_rate_from_rs_rate(mvm,
rate));
rs_table[index] = ucode_rate; if (toggle_ant)
rs_toggle_antenna(valid_tx_ant, rate);
}
if (!bottom_reached && !is_legacy(rate))
rate->index = prev_rate_idx;
*rs_table_index = index;
}
/* Building the rate table is non trivial. When we're in MIMO2/VHT/80Mhz/SGI * column the rate table should look like this: * * rate[0] 0x400F019 VHT | ANT: AB BW: 80Mhz MCS: 9 NSS: 2 SGI * rate[1] 0x400F019 VHT | ANT: AB BW: 80Mhz MCS: 9 NSS: 2 SGI * rate[2] 0x400F018 VHT | ANT: AB BW: 80Mhz MCS: 8 NSS: 2 SGI * rate[3] 0x400F018 VHT | ANT: AB BW: 80Mhz MCS: 8 NSS: 2 SGI * rate[4] 0x400F017 VHT | ANT: AB BW: 80Mhz MCS: 7 NSS: 2 SGI * rate[5] 0x400F017 VHT | ANT: AB BW: 80Mhz MCS: 7 NSS: 2 SGI * rate[6] 0x4005007 VHT | ANT: A BW: 80Mhz MCS: 7 NSS: 1 NGI * rate[7] 0x4009006 VHT | ANT: B BW: 80Mhz MCS: 6 NSS: 1 NGI * rate[8] 0x4005005 VHT | ANT: A BW: 80Mhz MCS: 5 NSS: 1 NGI * rate[9] 0x800B Legacy | ANT: B Rate: 36 Mbps * rate[10] 0x4009 Legacy | ANT: A Rate: 24 Mbps * rate[11] 0x8007 Legacy | ANT: B Rate: 18 Mbps * rate[12] 0x4005 Legacy | ANT: A Rate: 12 Mbps * rate[13] 0x800F Legacy | ANT: B Rate: 9 Mbps * rate[14] 0x400D Legacy | ANT: A Rate: 6 Mbps * rate[15] 0x800D Legacy | ANT: B Rate: 6 Mbps
*/ staticvoid rs_build_rates_table(struct iwl_mvm *mvm, struct ieee80211_sta *sta, struct iwl_lq_sta *lq_sta, conststruct rs_rate *initial_rate)
{ struct rs_rate rate; int num_rates, num_retries, index = 0;
u8 valid_tx_ant = 0; struct iwl_lq_cmd *lq_cmd = &lq_sta->lq; bool toggle_ant = false;
u32 color;
memcpy(&rate, initial_rate, sizeof(rate));
valid_tx_ant = iwl_mvm_get_valid_tx_ant(mvm);
/* TODO: remove old API when min FW API hits 14 */ if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_LQ_SS_PARAMS) &&
rs_stbc_allow(mvm, sta, lq_sta))
rate.stbc = true;
/* update the color of the LQ command (as a counter at bits 1-3) */
color = LQ_FLAGS_COLOR_INC(LQ_FLAG_COLOR_GET(lq_cmd->flags));
lq_cmd->flags = LQ_FLAG_COLOR_SET(lq_cmd->flags, color);
}
switch (viftype) { case NL80211_IFTYPE_AP: case NL80211_IFTYPE_P2P_GO:
prio = 3; break; case NL80211_IFTYPE_P2P_CLIENT:
prio = 2; break; case NL80211_IFTYPE_STATION:
prio = 1; break; default:
WARN_ONCE(true, "viftype %d sta_id %d", viftype,
sta->deflink.sta_id);
prio = -1;
}
return prio;
}
/* Returns >0 if sta1 has a higher BFER priority compared to sta2 */ staticint rs_bfer_priority_cmp(struct iwl_mvm_sta *sta1, struct iwl_mvm_sta *sta2)
{ int prio1 = rs_bfer_priority(sta1); int prio2 = rs_bfer_priority(sta2);
if (prio1 > prio2) return 1; if (prio1 < prio2) return -1; return 0;
}
if (!iwl_mvm_bt_coex_is_mimo_allowed(mvm, sta)) goto out;
#ifdef CONFIG_MAC80211_DEBUGFS /* Check if forcing the decision is configured. * Note that SISO is forced by not allowing STBC or BFER
*/ if (lq_sta->pers.ss_force == RS_SS_FORCE_STBC)
ss_params |= (LQ_SS_STBC_1SS_ALLOWED | LQ_SS_FORCE); elseif (lq_sta->pers.ss_force == RS_SS_FORCE_BFER)
ss_params |= (LQ_SS_BFER_ALLOWED | LQ_SS_FORCE);
if (lq_sta->pers.ss_force != RS_SS_FORCE_NONE) {
IWL_DEBUG_RATE(mvm, "Forcing single stream Tx decision %d\n",
lq_sta->pers.ss_force); goto out;
} #endif
if (lq_sta->stbc_capable)
ss_params |= LQ_SS_STBC_1SS_ALLOWED;
/* This code is safe as it doesn't run concurrently for different * stations. This is guaranteed by the fact that calls to * ieee80211_tx_status wouldn't run concurrently for a single HW.
*/ if (!bfer_mvmsta) {
IWL_DEBUG_RATE(mvm, "No sta with BFER allowed found. Allow\n");
ss_params |= LQ_SS_BFER_ALLOWED; goto out;
}
IWL_DEBUG_RATE(mvm, "Found existing sta %d with BFER activated\n",
bfer_mvmsta->deflink.sta_id);
/* Disallow BFER on another STA if active and we're a higher priority */ if (rs_bfer_priority_cmp(mvmsta, bfer_mvmsta) > 0) { struct iwl_lq_cmd *bfersta_lq_cmd =
&bfer_mvmsta->deflink.lq_sta.rs_drv.lq;
u32 bfersta_ss_params = le32_to_cpu(bfersta_lq_cmd->ss_params);
/* * In case of low latency, tell the firmware to leave a frame in the * Tx Fifo so that it can start a transaction in the same TxOP. This * basically allows the firmware to send bursts.
*/ if (iwl_mvm_vif_low_latency(mvmvif))
lq_cmd->agg_frame_cnt_limit--;
if (mvmsta->vif->p2p)
lq_cmd->flags |= LQ_FLAG_USE_RTS_MSK;
#ifdef CONFIG_MAC80211_DEBUGFS /* * Program the device to use fixed rate for frame transmit * This is for debugging/testing only * once the device start use fixed rate, we need to reload the module * to being back the normal operation.
*/ staticvoid rs_program_fix_rate(struct iwl_mvm *mvm, struct iwl_lq_sta *lq_sta)
{
lq_sta->active_legacy_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */
lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
lq_sta->active_mimo2_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
/* * Initialization of rate scaling information is done by driver after * the station is added. Since mac80211 calls this function before a * station is added we ignore it.
*/ staticvoid rs_rate_init_ops(void *mvm_r, struct ieee80211_supported_band *sband, struct cfg80211_chan_def *chandef, struct ieee80211_sta *sta, void *mvm_sta)
{
}
if ((he_type_bits == RATE_MCS_HE_TYPE_SU ||
he_type_bits == RATE_MCS_HE_TYPE_EXT_SU) &&
he_gi_ltf == RATE_MCS_HE_SU_4_LTF) /* the new rate have an additional bit to * represent the value 4 rather then using SGI * bit for this purpose - as it was done in the * old rate
*/
he_gi_ltf += (rate_v1 & RATE_MCS_SGI_MSK_V1) >>
RATE_MCS_SGI_POS_V1;
__le32 iwl_mvm_v3_rate_to_fw(u32 rate, u8 rate_ver)
{
u32 result = 0; int rate_idx;
if (rate_ver > 1) return iwl_v3_rate_to_v2_v3(rate, rate_ver > 2);
switch (rate & RATE_MCS_MOD_TYPE_MSK) { case RATE_MCS_MOD_TYPE_CCK:
result = RATE_MCS_CCK_MSK_V1;
fallthrough; case RATE_MCS_MOD_TYPE_LEGACY_OFDM:
rate_idx = u32_get_bits(rate, RATE_LEGACY_RATE_MSK); if (!(result & RATE_MCS_CCK_MSK_V1))
rate_idx += IWL_FIRST_OFDM_RATE;
result |= u32_encode_bits(iwl_fw_rate_idx_to_plcp(rate_idx),
RATE_LEGACY_RATE_MSK_V1); break; case RATE_MCS_MOD_TYPE_HT:
result = RATE_MCS_HT_MSK_V1;
result |= u32_encode_bits(u32_get_bits(rate,
RATE_HT_MCS_CODE_MSK),
RATE_HT_MCS_RATE_CODE_MSK_V1);
result |= u32_encode_bits(u32_get_bits(rate,
RATE_MCS_NSS_MSK),
RATE_HT_MCS_MIMO2_MSK); break; case RATE_MCS_MOD_TYPE_VHT:
result = RATE_MCS_VHT_MSK_V1;
result |= u32_encode_bits(u32_get_bits(rate,
RATE_VHT_MCS_NSS_MSK),
RATE_MCS_CODE_MSK);
result |= u32_encode_bits(u32_get_bits(rate, RATE_MCS_NSS_MSK),
RATE_VHT_MCS_NSS_MSK); break; case RATE_MCS_MOD_TYPE_HE: /* not generated */ default:
WARN_ONCE(1, "bad modulation type %d\n",
u32_get_bits(rate, RATE_MCS_MOD_TYPE_MSK)); return 0;
}
if (rate & RATE_MCS_LDPC_MSK)
result |= RATE_MCS_LDPC_MSK_V1;
WARN_ON_ONCE(u32_get_bits(rate, RATE_MCS_CHAN_WIDTH_MSK) >
RATE_MCS_CHAN_WIDTH_160_VAL);
result |= (rate & RATE_MCS_CHAN_WIDTH_MSK_V1) |
(rate & RATE_MCS_ANT_AB_MSK) |
(rate & RATE_MCS_STBC_MSK) |
(rate & RATE_MCS_BF_MSK);
/* not handling DUP since we don't use it */
WARN_ON_ONCE(rate & RATE_MCS_DUP_MSK);
if (rate & RATE_MCS_SGI_MSK)
result |= RATE_MCS_SGI_MSK_V1;
return cpu_to_le32(result);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.56 Sekunden
(vorverarbeitet am 2026-04-28)
¤
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.