#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;
}
/* * 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.
*/
/* * removes the old data from the statistics. All data that is older than * TID_MAX_TIME_DIFF, will be deleted.
*/ staticvoid rs_tl_rm_old_stats(struct iwl_traffic_load *tl, u32 curr_time)
{ /* The oldest age we want to keep */
u32 oldest_time = curr_time - TID_MAX_TIME_DIFF;
/* * increment traffic load value for tid and also remove * any old values if passed the certain time period
*/ static u8 rs_tl_add_packet(struct iwl_lq_sta *lq_data, struct ieee80211_hdr *hdr)
{
u32 curr_time = jiffies_to_msecs(jiffies);
u32 time_diff;
s32 index; struct iwl_traffic_load *tl = NULL;
u8 tid;
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);
if ((index + 1) > tl->queue_count)
tl->queue_count = index + 1;
return tid;
}
#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_priv *priv, struct iwl_lq_sta *lq_sta)
{ struct iwl_station_priv *sta_priv =
container_of(lq_sta, struct iwl_station_priv, lq_sta); struct iwl_rxon_context *ctx = sta_priv->ctx;
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 */
lq_sta->active_mimo3_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
/* get the traffic load value for tid
*/ staticvoid rs_tl_get_load(struct iwl_lq_sta *lq_data, u8 tid)
{
u32 curr_time = jiffies_to_msecs(jiffies);
u32 time_diff;
s32 index; struct iwl_traffic_load *tl = NULL;
if (tid >= IWL_MAX_TID_COUNT) return;
tl = &(lq_data->load[tid]);
curr_time -= curr_time % TID_ROUND_VALUE;
if (!(tl->queue_count)) return;
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't create TX aggregation sessions when in high * BT traffic, as they would just be disrupted by BT.
*/ 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;
}
rs_tl_get_load(lq_data, tid);
IWL_DEBUG_HT(priv, "Starting Tx agg: STA: %pM tid: %d\n",
sta->addr, tid);
ret = ieee80211_start_tx_ba_session(sta, tid, 5000); 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(priv, "Fail start Tx agg on tid: %d\n",
tid);
ieee80211_stop_tx_ba_session(sta, tid);
} return ret;
}
/* * 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_scale_tbl_info *tbl, int scale_index, int attempts, int successes)
{ struct iwl_rate_scale_data *window = NULL; staticconst u64 mask = (((u64)1) << (IWL_RATE_MAX_WINDOW - 1));
s32 fail_count, tpt;
if (scale_index < 0 || scale_index >= IWL_RATE_COUNT) return -EINVAL;
/* Select window for current tx bit rate */
window = &(tbl->win[scale_index]);
/* 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) {
/* 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;
return 0;
}
/* * Fill uCode API rate_n_flags field, based on "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) return 0;
if (!rs_is_valid_ant(valid_ant, tbl->ant_type)) return 0;
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];
/* * Green-field mode is valid if the station supports it and * there are no non-GF stations present in the BSS.
*/ staticbool rs_use_green(struct ieee80211_sta *sta)
{ /* * There's a bug somewhere in this code that causes the * scaling to get stuck because GF+SGI can't be combined * in SISO rates. Until we find that bug, disable GF, it * has only limited benefit and we still interoperate with * GF APs since we can always receive GF transmissions.
*/ returnfalse;
}
/* * rs_get_supported_rates - get the available rates * * if management frame or broadcast frame only return * basic available rates. *
*/ static u16 rs_get_supported_rates(struct iwl_lq_sta *lq_sta, struct ieee80211_hdr *hdr, enum iwl_table_type rate_type)
{ if (is_legacy(rate_type)) { return lq_sta->active_legacy_rate;
} else { if (is_siso(rate_type)) return lq_sta->active_siso_rate; elseif (is_mimo2(rate_type)) return lq_sta->active_mimo2_rate; else return lq_sta->active_mimo3_rate;
}
}
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. * assumption is that mandatory rates (1Mbps or 6Mbps)
* 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;
/* * 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;
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++; /* * mac80211 HT index is always zero-indexed; we need to move * HT OFDM rates after CCK rates in 2.4 GHz band
*/ 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); /* * 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_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;
/* Figure out if rate scale algorithm is in active or search table */ if (table_type_matches(&tbl_type,
&(lq_sta->lq_info[lq_sta->active_tbl]))) {
curr_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
other_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
} elseif (table_type_matches(&tbl_type,
&lq_sta->lq_info[1 - lq_sta->active_tbl])) {
curr_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
other_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
} else {
IWL_DEBUG_RATE(priv, "Neither active nor search matches tx rate\n");
tmp_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
IWL_DEBUG_RATE(priv, "active- lq:%x, ant:%x, SGI:%d\n",
tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI);
tmp_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
IWL_DEBUG_RATE(priv, "search- lq:%x, ant:%x, SGI:%d\n",
tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI);
IWL_DEBUG_RATE(priv, "actual- lq:%x, ant:%x, SGI:%d\n",
tbl_type.lq_type, tbl_type.ant_type, tbl_type.is_SGI); /* * 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) {
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);
rs_collect_tx_data(curr_tbl, rs_index,
info->status.ampdu_len,
info->status.ampdu_ack_len);
/* 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 { /* * 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) {
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); /* * Only collect stats if retried rate is in the same RS * table as active/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);
}
/* * 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_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;
}
/* * Find correct throughput table for given mode of modulation
*/ 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), channel width (20/40), SGI, and aggregation
* 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;
/* * Find starting rate for new "search" high-throughput mode of modulation. * Goal is to find lowest expected rate (under perfect conditions) that is * above the current measured throughput of "active" mode, to give new mode * a fair chance to prove itself without too many challenges. * * This gets called when transitioning to more aggressive modulation * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need * to decrease to match "active" throughput. When moving from MIMO to SISO, * bit rate will typically need to increase, but not if performance was bad.
*/ static s32 rs_get_best_rate(struct iwl_priv *priv, struct iwl_lq_sta *lq_sta, struct iwl_scale_tbl_info *tbl, /* "search" */
u16 rate_mask, s8 index)
{ /* "active" values */ struct iwl_scale_tbl_info *active_tbl =
&(lq_sta->lq_info[lq_sta->active_tbl]);
s32 active_sr = active_tbl->win[index].success_ratio;
s32 active_tpt = active_tbl->expected_tpt[index]; /* expected "search" throughput */ const u16 *tpt_tbl = tbl->expected_tpt;
/* * Lower the "search" bit rate, to give new "search" mode * approximately the same throughput as "active" if: * * 1) "Active" mode has been working modestly well (but not * great), and expected "search" throughput (under perfect * conditions) at candidate rate is above the actual * measured "active" throughput (but less than expected * "active" throughput under perfect conditions). * OR * 2) "Active" mode has been working perfectly or very well * and expected "search" throughput (under perfect * conditions) at candidate rate is above expected * "active" throughput (under perfect conditions).
*/ if ((((100 * tpt_tbl[rate]) > lq_sta->last_tpt) &&
((active_sr > IWL_RATE_DECREASE_TH) &&
(active_sr <= IWL_RATE_HIGH_TH) &&
(tpt_tbl[rate] <= active_tpt))) ||
((active_sr >= IWL_RATE_SCALE_SWITCH) &&
(tpt_tbl[rate] > active_tpt))) {
/* (2nd or later pass) * If we've already tried to raise the rate, and are
* 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) * If we've already tried to lower the rate, and are
* 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;
/* Set up new search table for MIMO2 */
memcpy(search_tbl, tbl, sz);
search_tbl->is_SGI = !tbl->is_SGI;
rs_set_expected_tpt_table(lq_sta, search_tbl); /* * If active table already uses the fastest possible * modulation (dual stream with short guard interval), * and it's working well, there's no need to look * for a better type of modulation!
*/ if (tbl->is_SGI) {
s32 tpt = lq_sta->last_tpt / 100; if (tpt >= search_tbl->expected_tpt[index]) break;
}
search_tbl->current_rate =
rate_n_flags_from_tbl(priv, search_tbl,
index, is_green);
update_search_tbl_counter = 1; goto out;
case IWL_MIMO2_SWITCH_MIMO3_ABC:
IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to MIMO3\n");
memcpy(search_tbl, tbl, sz);
search_tbl->is_SGI = 0;
search_tbl->ant_type = ANT_ABC;
if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) break;
ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
search_tbl, index); if (!ret) goto out;
break;
}
tbl->action++; if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
if (tbl->action == start_action) break;
}
search_tbl->lq_type = LQ_NONE; return;
out:
lq_sta->search_better_tbl = 1;
tbl->action++; if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
tbl->action = IWL_MIMO2_SWITCH_ANTENNA1; if (update_search_tbl_counter)
search_tbl->action = tbl->action;
/* 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);
/* Set up new search table for MIMO */
memcpy(search_tbl, tbl, sz);
search_tbl->is_SGI = !tbl->is_SGI;
rs_set_expected_tpt_table(lq_sta, search_tbl); /* * If active table already uses the fastest possible * modulation (dual stream with short guard interval), * and it's working well, there's no need to look * for a better type of modulation!
*/ if (tbl->is_SGI) {
s32 tpt = lq_sta->last_tpt / 100; if (tpt >= search_tbl->expected_tpt[index]) break;
}
search_tbl->current_rate =
rate_n_flags_from_tbl(priv, search_tbl,
index, is_green);
update_search_tbl_counter = 1; goto out;
}
tbl->action++; if (tbl->action > IWL_MIMO3_SWITCH_GI)
tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
if (tbl->action == start_action) break;
}
search_tbl->lq_type = LQ_NONE; return;
out:
lq_sta->search_better_tbl = 1;
tbl->action++; if (tbl->action > IWL_MIMO3_SWITCH_GI)
tbl->action = IWL_MIMO3_SWITCH_ANTENNA1; if (update_search_tbl_counter)
search_tbl->action = tbl->action;
}
/* * 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 i; int active_tbl; int flush_interval_passed = 0; struct iwl_priv *priv;
/* 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));
/* * 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(priv, "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->stay_in_tbl = 0; /* only place reset */
lq_sta->total_failed = 0;
lq_sta->total_success = 0;
lq_sta->flush_timer = 0;
/* * 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;
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 * bitmaps and stats in active table (this will become the new
* "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;
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.