#define IWL_RATE_MAX_WINDOW 62/* # tx in history window */ #define IWL_RATE_MIN_FAILURE_TH 6/* min failures to calc tpt */ #define IWL_RATE_MIN_SUCCESS_TH 8/* min successes to calc tpt */
/* max allowed rate miss before sync LQ cmd */ #define IWL_MISSED_RATE_MAX 15 /* max time to accum history 2 seconds */ #define IWL_RATE_SCALE_FLUSH_INTVL (3*HZ)
idx += IWL_FIRST_OFDM_RATE; /* skip 9M not supported in ht*/ if (idx >= IWL_RATE_9M_INDEX)
idx += 1; if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE)) return idx;
/* legacy rate format, search for match in table */
} else { for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++) if (iwl_rates[idx].plcp ==
rs_extract_rate(rate_n_flags)) return idx;
}
if (ieee80211_is_data_qos(hdr->frame_control)) {
u8 *qc = ieee80211_get_qos_ctl(hdr);
tid = qc[0] & 0xf;
} else return IWL_MAX_TID_COUNT;
if (unlikely(tid >= IWL_MAX_TID_COUNT)) return IWL_MAX_TID_COUNT;
tl = &lq_data->load[tid];
curr_time -= curr_time % TID_ROUND_VALUE;
/* Happens only for the first packet. Initialize the data */ if (!(tl->queue_count)) {
tl->total = 1;
tl->time_stamp = curr_time;
tl->queue_count = 1;
tl->head = 0;
tl->packet_count[0] = 1; return IWL_MAX_TID_COUNT;
}
time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
index = time_diff / TID_QUEUE_CELL_SPACING;
/* The history is too long: remove data that is older than */ /* TID_MAX_TIME_DIFF */ if (index >= TID_QUEUE_MAX_SIZE)
rs_tl_rm_old_stats(tl, curr_time);
time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
index = time_diff / TID_QUEUE_CELL_SPACING;
/* The history is too long: remove data that is older than */ /* TID_MAX_TIME_DIFF */ if (index >= TID_QUEUE_MAX_SIZE)
rs_tl_rm_old_stats(tl, curr_time);
}
staticint rs_tl_turn_on_agg_for_tid(struct iwl_priv *priv, struct iwl_lq_sta *lq_data, u8 tid, struct ieee80211_sta *sta)
{ int ret = -EAGAIN;
/* *Don'tcreateTXaggregationsessionswheninhigh *BTtraffic,astheywouldjustbedisruptedbyBT.
*/ if (priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) {
IWL_DEBUG_COEX(priv, "BT traffic (%d), no aggregation allowed\n",
priv->bt_traffic_load); return ret;
}
/* Calculate average throughput, if we have enough history. */ if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) ||
(window->success_counter >= IWL_RATE_MIN_SUCCESS_TH))
window->average_tpt = (window->success_ratio * tpt + 64) / 128; else
window->average_tpt = IWL_INVALID_VALUE;
/* Tag this window as having been updated */
window->stamp = jiffies;
return0;
}
/* *FilluCodeAPIrate_n_flagsfield,basedon"search"or"active"table.
*/ /* FIXME:RS:remove this function and put the flags statically in the table */ static u32 rate_n_flags_from_tbl(struct iwl_priv *priv, struct iwl_scale_tbl_info *tbl, int index, u8 use_green)
{
u32 rate_n_flags = 0;
if (is_legacy(tbl->lq_type)) {
rate_n_flags = iwl_rates[index].plcp; if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
rate_n_flags |= RATE_MCS_CCK_MSK;
} elseif (is_Ht(tbl->lq_type)) { if (index > IWL_LAST_OFDM_RATE) {
IWL_ERR(priv, "Invalid HT rate index %d\n", index);
index = IWL_LAST_OFDM_RATE;
}
rate_n_flags = RATE_MCS_HT_MSK;
/* switch to another antenna/antennas and return 1 */ /* if no other valid antenna found, return 0 */ staticint rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags, struct iwl_scale_tbl_info *tbl)
{
u8 new_ant_type;
if (!tbl->ant_type || tbl->ant_type > ANT_ABC) return0;
if (!rs_is_valid_ant(valid_ant, tbl->ant_type)) return0;
new_ant_type = ant_toggle_lookup[tbl->ant_type];
while ((new_ant_type != tbl->ant_type) &&
!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_priv *priv, 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_a_band(rate_type) || !is_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;
}
}
/* check if we need to switch from HT to legacy rates. *assumptionisthatmandatoryrates(1Mbpsor6Mbps)
* are always supported (spec demand) */ if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) {
switch_to_legacy = 1;
scale_index = rs_ht_to_legacy[scale_index]; if (lq_sta->band == NL80211_BAND_5GHZ)
tbl->lq_type = LQ_A; else
tbl->lq_type = LQ_G;
if (num_of_ant(tbl->ant_type) > 1)
tbl->ant_type =
first_antenna(priv->nvm_data->valid_tx_ant);
/* Mask with station rate restriction */ if (is_legacy(tbl->lq_type)) { /* supp_rates has no CCK bits in A mode */ if (lq_sta->band == NL80211_BAND_5GHZ)
rate_mask = (u16)(rate_mask &
(lq_sta->supp_rates << IWL_FIRST_OFDM_RATE)); else
rate_mask = (u16)(rate_mask & lq_sta->supp_rates);
}
/* If we switched from HT to legacy, check current rate */ if (switch_to_legacy && (rate_mask & (1 << scale_index))) {
low = scale_index; goto out;
}
/* Treat uninitialized rate scaling data same as non-existing. */ if (!lq_sta) {
IWL_DEBUG_RATE(priv, "Station rate scaling not created yet.\n"); return;
} elseif (!lq_sta->drv) {
IWL_DEBUG_RATE(priv, "Rate scaling not initialized yet.\n"); return;
}
if (!ieee80211_is_data(hdr->frame_control) ||
info->flags & IEEE80211_TX_CTL_NO_ACK) 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;
/* *IgnorethisTxframeresponseifitsinitialratedoesn'tmatch *thatoflatestLinkQualitycommand.Theremaybestragglers *fromapreviousLinkQualitycommand,butwe'renolongerinterested *inthose;they'reeitherfromthe"active"modewhilewe'retrying *tocheck"search"mode,oraprior"search"modeafterwe'vemoved *toanew"search"mode(whichmightbecomethenew"active"mode).
*/
table = &lq_sta->lq;
tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags);
rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index); if (priv->band == NL80211_BAND_5GHZ)
rs_index -= IWL_FIRST_OFDM_RATE;
mac_flags = info->status.rates[0].flags;
mac_index = info->status.rates[0].idx; /* For HT packets, map MCS to PLCP */ if (mac_flags & IEEE80211_TX_RC_MCS) {
mac_index &= RATE_MCS_CODE_MSK; /* Remove # of streams */ if (mac_index >= (IWL_RATE_9M_INDEX - IWL_FIRST_OFDM_RATE))
mac_index++; /* *mac80211HTindexisalwayszero-indexed;weneedtomove *HTOFDMratesafterCCKratesin2.4GHzband
*/ if (priv->band == NL80211_BAND_2GHZ)
mac_index += IWL_FIRST_OFDM_RATE;
} /* Here we actually compare this rate to the latest LQ command */ if ((mac_index < 0) ||
(tbl_type.is_SGI != !!(mac_flags & IEEE80211_TX_RC_SHORT_GI)) ||
(tbl_type.is_ht40 != !!(mac_flags & IEEE80211_TX_RC_40_MHZ_WIDTH)) ||
(tbl_type.is_dup != !!(mac_flags & IEEE80211_TX_RC_DUP_DATA)) ||
(tbl_type.ant_type != info->status.antenna) ||
(!!(tx_rate & RATE_MCS_HT_MSK) != !!(mac_flags & IEEE80211_TX_RC_MCS)) ||
(!!(tx_rate & RATE_MCS_GF_MSK) != !!(mac_flags & IEEE80211_TX_RC_GREEN_FIELD)) ||
(rs_index != mac_index)) {
IWL_DEBUG_RATE(priv, "initial rate %d does not match %d (0x%x)\n", mac_index, rs_index, tx_rate); /* *Sinceratesmis-match,thelastLQcommandmayhavefailed. *AfterIWL_MISSED_RATE_MAXmis-matches,resynctheuCodewith *...driver.
*/
lq_sta->missed_rate_counter++; if (lq_sta->missed_rate_counter > IWL_MISSED_RATE_MAX) {
lq_sta->missed_rate_counter = 0;
iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
} /* Regardless, ignore this status info for outdated rate */ return;
} else /* Rate did match, so reset the missed_rate_counter */
lq_sta->missed_rate_counter = 0;
/* Update success/fail counts if not searching for new mode */ if (lq_sta->stay_in_tbl) {
lq_sta->total_success += info->status.ampdu_ack_len;
lq_sta->total_failed += (info->status.ampdu_len -
info->status.ampdu_ack_len);
}
} else { /* *Forlegacy,updateframehistorywithforeachTxretry.
*/
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) {
tx_rate = le32_to_cpu(table->rs_table[i].rate_n_flags);
rs_get_tbl_info_from_mcs(tx_rate, priv->band,
&tbl_type, &rs_index); /* *OnlycollectstatsifretriedrateisinthesameRS *tableasactive/search.
*/ if (table_type_matches(&tbl_type, curr_tbl))
tmp_tbl = curr_tbl; elseif (table_type_matches(&tbl_type, other_tbl))
tmp_tbl = other_tbl; else continue;
rs_collect_tx_data(tmp_tbl, rs_index, 1,
i < retries ? 0 : legacy_success);
}
/* Update success/fail counts if not searching for new mode */ if (lq_sta->stay_in_tbl) {
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 = tx_rate;
done: /* See if there's a better rate or modulation mode to try. */ if (sta && sta->deflink.supp_rates[sband->band])
rs_rate_scale_perform(priv, skb, sta, lq_sta);
if (priv->lib->bt_params && priv->lib->bt_params->advanced_bt_coexist)
rs_bt_update_lq(priv, ctx, lq_sta);
}
/* *Beginaperiodofstayingwithaselectedmodulationmode. *Set"stay_in_tbl"flagtopreventanymodeswitches. *Setframetxsuccesslimitsaccordingtolegacyvs.high-throughput, *andresetoverall(spanningallrates)txsuccesshistorystatistics. *Thesecontrolhowlongwestayusingsamemodulationmodebefore *searchingforanewmode.
*/ staticvoid rs_set_stay_in_table(struct iwl_priv *priv, u8 is_legacy, struct iwl_lq_sta *lq_sta)
{
IWL_DEBUG_RATE(priv, "we are staying in the same table\n");
lq_sta->stay_in_tbl = 1; /* only place this gets set */ if (is_legacy) {
lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT;
lq_sta->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT;
lq_sta->max_success_limit = IWL_LEGACY_SUCCESS_LIMIT;
} else {
lq_sta->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT;
lq_sta->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT;
lq_sta->max_success_limit = IWL_NONE_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->action_counter = 0;
}
/* *Findcorrectthroughputtableforgivenmodeofmodulation
*/ staticvoid rs_set_expected_tpt_table(struct iwl_lq_sta *lq_sta, struct iwl_scale_tbl_info *tbl)
{ /* Used to choose among HT tables */ const u16 (*ht_tbl_pointer)[IWL_RATE_COUNT];
/* Check for invalid LQ type */ if (WARN_ON_ONCE(!is_legacy(tbl->lq_type) && !is_Ht(tbl->lq_type))) {
tbl->expected_tpt = expected_tpt_legacy; return;
}
/* Legacy rates have only one table */ if (is_legacy(tbl->lq_type)) {
tbl->expected_tpt = expected_tpt_legacy; return;
}
/* Choose among many HT tables depending on number of streams *(SISO/MIMO2/MIMO3),channelwidth(20/40),SGI,andaggregation
* status */ if (is_siso(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
ht_tbl_pointer = expected_tpt_siso20MHz; elseif (is_siso(tbl->lq_type))
ht_tbl_pointer = expected_tpt_siso40MHz; elseif (is_mimo2(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
ht_tbl_pointer = expected_tpt_mimo2_20MHz; elseif (is_mimo2(tbl->lq_type))
ht_tbl_pointer = expected_tpt_mimo2_40MHz; elseif (is_mimo3(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup))
ht_tbl_pointer = expected_tpt_mimo3_20MHz; else/* if (is_mimo3(tbl->lq_type)) <-- must be true */
ht_tbl_pointer = expected_tpt_mimo3_40MHz;
/* (2nd or later pass) *Ifwe'vealreadytriedtoraisetherate,andare
* now trying to lower it, use the higher rate. */ if (start_hi != IWL_RATE_INVALID) {
new_rate = start_hi; break;
}
new_rate = rate;
/* Loop again with lower rate */ if (low != IWL_RATE_INVALID)
rate = low;
/* Lower rate not available, use the original */ else break;
/* Else try to raise the "search" rate to match "active" */
} else { /* (2nd or later pass) *Ifwe'vealreadytriedtolowertherate,andare
* now trying to raise it, use the lower rate. */ if (new_rate != IWL_RATE_INVALID) break;
/* Loop again with higher rate */ elseif (high != IWL_RATE_INVALID) {
start_hi = high;
rate = high;
/* Higher rate not available, use the original */
} else {
new_rate = rate; break;
}
}
}
/* Don't change antenna if success has been great */ if (window->success_ratio >= IWL_RS_GOOD_RATIO &&
!priv->bt_full_concurrent &&
priv->bt_traffic_load ==
IWL_BT_COEX_TRAFFIC_LOAD_NONE) break;
/* Set up search table to try other antenna */
memcpy(search_tbl, tbl, sz);
if (rs_toggle_antenna(valid_tx_ant,
&search_tbl->current_rate, search_tbl)) {
update_search_tbl_counter = 1;
rs_set_expected_tpt_table(lq_sta, search_tbl); goto out;
} break; case IWL_LEGACY_SWITCH_SISO:
IWL_DEBUG_RATE(priv, "LQ: Legacy switch to SISO\n");
/* Set up search table to try SISO */
memcpy(search_tbl, tbl, sz);
search_tbl->is_SGI = 0;
ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
search_tbl, index); if (!ret) {
lq_sta->action_counter = 0; goto out;
}
break; case IWL_LEGACY_SWITCH_MIMO2_AB: case IWL_LEGACY_SWITCH_MIMO2_AC: case IWL_LEGACY_SWITCH_MIMO2_BC:
IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO2\n");
/* Set up search table to try MIMO */
memcpy(search_tbl, tbl, sz);
search_tbl->is_SGI = 0;
switch (priv->bt_traffic_load) { case IWL_BT_COEX_TRAFFIC_LOAD_NONE: /* nothing */ break; case IWL_BT_COEX_TRAFFIC_LOAD_LOW: /* avoid antenna B unless MIMO */ if (tbl->action == IWL_SISO_SWITCH_ANTENNA2)
tbl->action = IWL_SISO_SWITCH_MIMO2_AB; break; case IWL_BT_COEX_TRAFFIC_LOAD_HIGH: case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: /* avoid antenna B and MIMO */
valid_tx_ant =
first_antenna(priv->nvm_data->valid_tx_ant); if (tbl->action != IWL_SISO_SWITCH_ANTENNA1)
tbl->action = IWL_SISO_SWITCH_ANTENNA1; break; default:
IWL_ERR(priv, "Invalid BT load %d\n", priv->bt_traffic_load); break;
}
if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE &&
tbl->action > IWL_SISO_SWITCH_ANTENNA2) { /* stay in SISO */
tbl->action = IWL_SISO_SWITCH_ANTENNA1;
}
/* configure as 1x1 if bt full concurrency */ if (priv->bt_full_concurrent) {
valid_tx_ant =
first_antenna(priv->nvm_data->valid_tx_ant); if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2)
tbl->action = IWL_SISO_SWITCH_ANTENNA1;
}
start_action = tbl->action; for (;;) {
lq_sta->action_counter++; switch (tbl->action) { case IWL_SISO_SWITCH_ANTENNA1: case IWL_SISO_SWITCH_ANTENNA2:
IWL_DEBUG_RATE(priv, "LQ: SISO toggle Antenna\n"); if ((tbl->action == IWL_SISO_SWITCH_ANTENNA1 &&
tx_chains_num <= 1) ||
(tbl->action == IWL_SISO_SWITCH_ANTENNA2 &&
tx_chains_num <= 2)) break;
/* configure as 1x1 if bt full concurrency */ if (priv->bt_full_concurrent &&
(tbl->action < IWL_MIMO3_SWITCH_SISO_A ||
tbl->action > IWL_MIMO3_SWITCH_SISO_C))
tbl->action = IWL_MIMO3_SWITCH_SISO_A;
start_action = tbl->action; for (;;) {
lq_sta->action_counter++; switch (tbl->action) { case IWL_MIMO3_SWITCH_ANTENNA1: case IWL_MIMO3_SWITCH_ANTENNA2:
IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle Antennas\n");
if (tx_chains_num <= 3) break;
if (window->success_ratio >= IWL_RS_GOOD_RATIO) break;
memcpy(search_tbl, tbl, sz); if (rs_toggle_antenna(valid_tx_ant,
&search_tbl->current_rate, search_tbl)) goto out; break; case IWL_MIMO3_SWITCH_SISO_A: case IWL_MIMO3_SWITCH_SISO_B: case IWL_MIMO3_SWITCH_SISO_C:
IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to SISO\n");
/* Set up new search table for SISO */
memcpy(search_tbl, tbl, sz);
/* If we've been disallowing search, see if we should now allow it */ if (lq_sta->stay_in_tbl) {
/* Elapsed time using current modulation mode */ if (lq_sta->flush_timer)
flush_interval_passed =
time_after(jiffies,
(unsignedlong)(lq_sta->flush_timer +
IWL_RATE_SCALE_FLUSH_INTVL));
IWL_DEBUG_RATE(priv, "LQ: stay in table clear win\n"); for (i = 0; i < IWL_RATE_COUNT; i++)
rs_rate_scale_clear_window(
&(tbl->win[i]));
}
}
/* If transitioning to allow "search", reset all history *bitmapsandstatsinactivetable(thiswillbecomethenew
* "search" table). */ if (!lq_sta->stay_in_tbl) { for (i = 0; i < IWL_RATE_COUNT; i++)
rs_rate_scale_clear_window(&(tbl->win[i]));
}
}
}
IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n");
/* Send management frames and NO_ACK data using lowest rate. */ /* TODO: this could probably be improved.. */ if (!ieee80211_is_data(hdr->frame_control) ||
info->flags & IEEE80211_TX_CTL_NO_ACK) return;
/* current tx rate */
index = lq_sta->last_txrate_idx;
IWL_DEBUG_RATE(priv, "Rate scale index %d for type %d\n", index,
tbl->lq_type);
/* rates available for this association, and for modulation mode */
rate_mask = rs_get_supported_rates(lq_sta, hdr, tbl->lq_type);
IWL_DEBUG_RATE(priv, "mask 0x%04X\n", rate_mask);
/* mask with station rate restriction */ if (is_legacy(tbl->lq_type)) { if (lq_sta->band == NL80211_BAND_5GHZ) /* supp_rates has no CCK bits in A mode */
rate_scale_index_msk = (u16) (rate_mask &
(lq_sta->supp_rates << IWL_FIRST_OFDM_RATE)); else
rate_scale_index_msk = (u16) (rate_mask &
lq_sta->supp_rates);
} else
rate_scale_index_msk = rate_mask;
if (!rate_scale_index_msk)
rate_scale_index_msk = rate_mask;
if (!((1 << index) & rate_scale_index_msk)) {
IWL_ERR(priv, "Current Rate is not valid\n"); if (lq_sta->search_better_tbl) { /* revert to active table if search table is not valid*/
tbl->lq_type = LQ_NONE;
lq_sta->search_better_tbl = 0;
tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); /* get "active" rate info */
index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
rs_update_rate_tbl(priv, ctx, lq_sta, tbl,
index, is_green);
} return;
}
/* Get expected throughput table and history window for current rate */ if (!tbl->expected_tpt) {
IWL_ERR(priv, "tbl->expected_tpt is NULL\n"); return;
}
/* force user max rate if set by user */ if ((lq_sta->max_rate_idx != -1) &&
(lq_sta->max_rate_idx < index)) {
index = lq_sta->max_rate_idx;
update_lq = 1;
window = &(tbl->win[index]); goto lq_update;
}
/* 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);
goto out;
} /* Else we have enough samples; calculate estimate of
* actual average throughput */ if (window->average_tpt != ((window->success_ratio *
tbl->expected_tpt[index] + 64) / 128)) {
IWL_ERR(priv, "expected_tpt should have been calculated by now\n");
window->average_tpt = ((window->success_ratio *
tbl->expected_tpt[index] + 64) / 128);
}
/* If we are searching for better modulation mode, check success. */ if (lq_sta->search_better_tbl &&
(iwl_tx_ant_restriction(priv) == IWL_ANT_OK_MULTI)) { /* If good success, continue using the "search" mode; *noneedtosendnewlinkqualitycommand,sincewe're
* continuing to use the setup that we've been trying. */ if (window->average_tpt > lq_sta->last_tpt) {
IWL_DEBUG_RATE(priv, "LQ: SWITCHING TO NEW TABLE " "suc=%d cur-tpt=%d old-tpt=%d\n",
window->success_ratio,
window->average_tpt,
lq_sta->last_tpt);
if (!is_legacy(tbl->lq_type))
lq_sta->enable_counter = 1;
/* Else poor success; go back to mode in "active" table */
} else {
IWL_DEBUG_RATE(priv, "LQ: GOING BACK TO THE OLD TABLE " "suc=%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 = iwl_hwrate_to_plcp_idx(tbl->current_rate);
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(priv, index, rate_scale_index_msk,
tbl->lq_type);
low = high_low & 0xff;
high = (high_low >> 8) & 0xff;
/* If user set max rate, dont allow higher than user constrain */ if ((lq_sta->max_rate_idx != -1) &&
(lq_sta->max_rate_idx < high))
high = IWL_RATE_INVALID;
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;
scale_action = 0;
/* Too many failures, decrease rate */ if ((sr <= IWL_RATE_DECREASE_TH) || (current_tpt == 0)) {
IWL_DEBUG_RATE(priv, "decrease rate because of low success_ratio\n");
scale_action = -1;
if (high != IWL_RATE_INVALID && sr >= IWL_RATE_INCREASE_TH)
scale_action = 1; elseif (low != IWL_RATE_INVALID)
scale_action = 0;
}
/* Both adjacent throughputs are measured, but neither one has better
* throughput; we're using the best rate, don't change it! */ elseif ((low_tpt != IWL_INVALID_VALUE) &&
(high_tpt != IWL_INVALID_VALUE) &&
(low_tpt < current_tpt) &&
(high_tpt < current_tpt))
scale_action = 0;
/* At least one adjacent rate's throughput is measured,
* and may have better performance. */ else { /* Higher adjacent rate's throughput is measured */ if (high_tpt != IWL_INVALID_VALUE) { /* Higher rate has better throughput */ if (high_tpt > current_tpt &&
sr >= IWL_RATE_INCREASE_TH) {
scale_action = 1;
} else {
scale_action = 0;
}
/* Lower adjacent rate's throughput is measured */
} elseif (low_tpt != IWL_INVALID_VALUE) { /* Lower rate has better throughput */ if (low_tpt > current_tpt) {
IWL_DEBUG_RATE(priv, "decrease rate because of low tpt\n");
scale_action = -1;
} elseif (sr >= IWL_RATE_INCREASE_TH) {
scale_action = 1;
}
}
}
/* Sanity check; asked for decrease, but success rate or throughput
* has been good at old rate. Don't change it. */ if ((scale_action == -1) && (low != IWL_RATE_INVALID) &&
((sr > IWL_RATE_HIGH_TH) ||
(current_tpt > (100 * tbl->expected_tpt[low]))))
scale_action = 0; if (!iwl_ht_enabled(priv) && !is_legacy(tbl->lq_type))
scale_action = -1; if (iwl_tx_ant_restriction(priv) != IWL_ANT_OK_MULTI &&
(is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type)))
scale_action = -1;
IWL_DEBUG_RATE(priv, "choose rate scale index %d action %d low %d " "high %d type %d\n",
index, scale_action, low, high, tbl->lq_type);
lq_update: /* Replace uCode's rate table for the destination station. */ if (update_lq)
rs_update_rate_tbl(priv, ctx, lq_sta, tbl, index, is_green);
if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_MULTI) { /* Should we stay with this modulation mode,
* or search for a new one? */
rs_stay_in_table(lq_sta, false);
} /* *Searchfornewmodulationmodeifwe're: *1)Notchangingratesrightnow *2)Notjustfinishingupasearch *3)Allowinganewsearch
*/ if (!update_lq && !done_search && !lq_sta->stay_in_tbl && window->counter) { /* Save current throughput to compare with "search" throughput*/
lq_sta->last_tpt = current_tpt;
/* Select a new "search" modulation mode to try.
* If one is found, set up the new "search" table. */ if (is_legacy(tbl->lq_type))
rs_move_legacy_other(priv, lq_sta, conf, sta, index); elseif (is_siso(tbl->lq_type))
rs_move_siso_to_other(priv, lq_sta, conf, sta, index); elseif (is_mimo2(tbl->lq_type))
rs_move_mimo2_to_other(priv, lq_sta, conf, sta, index); else
rs_move_mimo3_to_other(priv, lq_sta, conf, sta, index);
/* 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[(1 - lq_sta->active_tbl)]); for (i = 0; i < IWL_RATE_COUNT; i++)
rs_rate_scale_clear_window(&(tbl->win[i]));
/* Use new "search" start rate */
index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
if (done_search && !lq_sta->stay_in_tbl) { /* If the "active" (non-search) mode was legacy, *andwe'vetriedswitchingantennas, *butwehaven'tbeenabletotryHTmodes(notavailable), *staywithbestantennalegacymodulationforawhile
* before next round of mode comparisons. */
tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]); if (is_legacy(tbl1->lq_type) && !conf_is_ht(conf) &&
lq_sta->action_counter > tbl1->max_search) {
IWL_DEBUG_RATE(priv, "LQ: STAY in legacy table\n");
rs_set_stay_in_table(priv, 1, lq_sta);
}
/* If we're in an HT mode, and all 3 mode switch actions *havebeentriedandcompared,stayinthisbestmodulation
* mode for a while before next round of mode comparisons. */ if (lq_sta->enable_counter &&
(lq_sta->action_counter >= tbl1->max_search) &&
iwl_ht_enabled(priv)) { if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) &&
(lq_sta->tx_agg_tid_en & (1 << tid)) &&
(tid != IWL_MAX_TID_COUNT)) {
u8 sta_id = lq_sta->lq.sta_id;
tid_data = &priv->tid_data[sta_id][tid]; if (tid_data->agg.state == IWL_AGG_OFF) {
IWL_DEBUG_RATE(priv, "try to aggregate tid %d\n",
tid);
rs_tl_turn_on_agg(priv, tid,
lq_sta, sta);
}
}
rs_set_stay_in_table(priv, 0, lq_sta);
}
}
IWL_DEBUG_RATE_LIMIT(priv, "rate scale calculate new rate for skb\n");
/* Get max rate if user set max rate */
lq_sta->max_rate_idx = fls(txrc->rate_idx_mask) - 1; if (sband->band == NL80211_BAND_5GHZ && lq_sta->max_rate_idx != -1)
lq_sta->max_rate_idx += IWL_FIRST_OFDM_RATE; if (lq_sta->max_rate_idx < 0 || lq_sta->max_rate_idx >= IWL_RATE_COUNT)
lq_sta->max_rate_idx = -1;
if (!lq_sta->drv) {
IWL_DEBUG_RATE(priv, "Rate scaling not initialized yet.\n"); /* mac80211 already set up the data for using low rates */ return;
}
IWL_DEBUG_RATE(priv, "LQ: *** rate scale station global init for station %d ***\n",
sta_id); /* TODO: what is a good starting rate for STA? About middle? Maybe not *thelowestorthehighestrate..CouldconsiderusingRSSIfrom *previouspackets?NeedtohaveIEEE802.1Xauthsucceedimmediately
* after assoc.. */
if (priv && priv->bt_full_concurrent) { /* 1x1 only */
tbl_type.ant_type =
first_antenna(priv->nvm_data->valid_tx_ant);
}
/* How many times should we repeat the initial rate? */ if (is_legacy(tbl_type.lq_type)) {
ant_toggle_cnt = 1;
repeat_rate = IWL_NUMBER_TRY;
} else {
repeat_rate = min(IWL_HT_NUMBER_TRY,
LINK_QUAL_AGG_DISABLE_START_DEF - 1);
}
if (priv && priv->bt_full_concurrent) { /* 1x1 only */
tbl_type.ant_type =
first_antenna(priv->nvm_data->valid_tx_ant);
}
/* Indicate to uCode which entries might be MIMO. *IfinitialratewasMIMO,thiswillfinallyendup
* as (IWL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */ if (is_mimo(tbl_type.lq_type))
lq_cmd->general_params.mimo_delimiter = index;
/* Get next rate */
new_rate = rs_get_lower_rate(lq_sta, &tbl_type, rate_idx,
use_ht_possible);
/* How many times should we repeat the next rate? */ if (is_legacy(tbl_type.lq_type)) { if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
ant_toggle_cnt++; elseif (priv &&
rs_toggle_antenna(valid_tx_ant,
&new_rate, &tbl_type))
ant_toggle_cnt = 1;
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.