Commit 74221d07 authored by Abbas, Mohamed's avatar Abbas, Mohamed Committed by John W. Linville

iwl3945: Fix iwl3945 rate scaling.

3945 rate scaling was broken in recent tree. This patch fix the following:
	1- Get TX response info and update rates window.
	2- Rate scaling selection.
	3- Flush window timer.
Signed-off-by: default avatarMohamed Abbas <mohamed.abbas@intel.com>
Signed-off-by: default avatarReinette Chatre <reinette.chatre@intel.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent c30e30e1
...@@ -117,9 +117,11 @@ static struct iwl3945_tpt_entry iwl3945_tpt_table_g[] = { ...@@ -117,9 +117,11 @@ static struct iwl3945_tpt_entry iwl3945_tpt_table_g[] = {
}; };
#define IWL_RATE_MAX_WINDOW 62 #define IWL_RATE_MAX_WINDOW 62
#define IWL_RATE_FLUSH (3*HZ/10) #define IWL_RATE_FLUSH (3*HZ)
#define IWL_RATE_WIN_FLUSH (HZ/2) #define IWL_RATE_WIN_FLUSH (HZ/2)
#define IWL_RATE_HIGH_TH 11520 #define IWL_RATE_HIGH_TH 11520
#define IWL_SUCCESS_UP_TH 8960
#define IWL_SUCCESS_DOWN_TH 10880
#define IWL_RATE_MIN_FAILURE_TH 8 #define IWL_RATE_MIN_FAILURE_TH 8
#define IWL_RATE_MIN_SUCCESS_TH 8 #define IWL_RATE_MIN_SUCCESS_TH 8
#define IWL_RATE_DECREASE_TH 1920 #define IWL_RATE_DECREASE_TH 1920
...@@ -206,6 +208,7 @@ static int iwl3945_rate_scale_flush_windows(struct iwl3945_rs_sta *rs_sta) ...@@ -206,6 +208,7 @@ static int iwl3945_rate_scale_flush_windows(struct iwl3945_rs_sta *rs_sta)
#define IWL_RATE_FLUSH_MAX 5000 /* msec */ #define IWL_RATE_FLUSH_MAX 5000 /* msec */
#define IWL_RATE_FLUSH_MIN 50 /* msec */ #define IWL_RATE_FLUSH_MIN 50 /* msec */
#define IWL_AVERAGE_PACKETS 1500
static void iwl3945_bg_rate_scale_flush(unsigned long data) static void iwl3945_bg_rate_scale_flush(unsigned long data)
{ {
...@@ -220,8 +223,6 @@ static void iwl3945_bg_rate_scale_flush(unsigned long data) ...@@ -220,8 +223,6 @@ static void iwl3945_bg_rate_scale_flush(unsigned long data)
spin_lock_irqsave(&rs_sta->lock, flags); spin_lock_irqsave(&rs_sta->lock, flags);
rs_sta->flush_pending = 0;
/* Number of packets Rx'd since last time this timer ran */ /* Number of packets Rx'd since last time this timer ran */
packet_count = (rs_sta->tx_packets - rs_sta->last_tx_packets) + 1; packet_count = (rs_sta->tx_packets - rs_sta->last_tx_packets) + 1;
...@@ -230,7 +231,6 @@ static void iwl3945_bg_rate_scale_flush(unsigned long data) ...@@ -230,7 +231,6 @@ static void iwl3945_bg_rate_scale_flush(unsigned long data)
if (unflushed) { if (unflushed) {
duration = duration =
jiffies_to_msecs(jiffies - rs_sta->last_partial_flush); jiffies_to_msecs(jiffies - rs_sta->last_partial_flush);
/* duration = jiffies_to_msecs(rs_sta->flush_time); */
IWL_DEBUG_RATE("Tx'd %d packets in %dms\n", IWL_DEBUG_RATE("Tx'd %d packets in %dms\n",
packet_count, duration); packet_count, duration);
...@@ -242,9 +242,11 @@ static void iwl3945_bg_rate_scale_flush(unsigned long data) ...@@ -242,9 +242,11 @@ static void iwl3945_bg_rate_scale_flush(unsigned long data)
pps = 0; pps = 0;
if (pps) { if (pps) {
duration = IWL_RATE_FLUSH_MAX / pps; duration = (IWL_AVERAGE_PACKETS * 1000) / pps;
if (duration < IWL_RATE_FLUSH_MIN) if (duration < IWL_RATE_FLUSH_MIN)
duration = IWL_RATE_FLUSH_MIN; duration = IWL_RATE_FLUSH_MIN;
else if (duration > IWL_RATE_FLUSH_MAX)
duration = IWL_RATE_FLUSH_MAX;
} else } else
duration = IWL_RATE_FLUSH_MAX; duration = IWL_RATE_FLUSH_MAX;
...@@ -257,8 +259,10 @@ static void iwl3945_bg_rate_scale_flush(unsigned long data) ...@@ -257,8 +259,10 @@ static void iwl3945_bg_rate_scale_flush(unsigned long data)
rs_sta->flush_time); rs_sta->flush_time);
rs_sta->last_partial_flush = jiffies; rs_sta->last_partial_flush = jiffies;
} else {
rs_sta->flush_time = IWL_RATE_FLUSH;
rs_sta->flush_pending = 0;
} }
/* If there weren't any unflushed entries, we don't schedule the timer /* If there weren't any unflushed entries, we don't schedule the timer
* to run again */ * to run again */
...@@ -278,17 +282,18 @@ static void iwl3945_bg_rate_scale_flush(unsigned long data) ...@@ -278,17 +282,18 @@ static void iwl3945_bg_rate_scale_flush(unsigned long data)
*/ */
static void iwl3945_collect_tx_data(struct iwl3945_rs_sta *rs_sta, static void iwl3945_collect_tx_data(struct iwl3945_rs_sta *rs_sta,
struct iwl3945_rate_scale_data *window, struct iwl3945_rate_scale_data *window,
int success, int retries) int success, int retries, int index)
{ {
unsigned long flags; unsigned long flags;
s32 fail_count;
if (!retries) { if (!retries) {
IWL_DEBUG_RATE("leave: retries == 0 -- should be at least 1\n"); IWL_DEBUG_RATE("leave: retries == 0 -- should be at least 1\n");
return; return;
} }
while (retries--) {
spin_lock_irqsave(&rs_sta->lock, flags); spin_lock_irqsave(&rs_sta->lock, flags);
while (retries--) {
/* If we have filled up the window then subtract one from the /* If we have filled up the window then subtract one from the
* success counter if the high-bit is counting toward * success counter if the high-bit is counting toward
...@@ -316,8 +321,18 @@ static void iwl3945_collect_tx_data(struct iwl3945_rs_sta *rs_sta, ...@@ -316,8 +321,18 @@ static void iwl3945_collect_tx_data(struct iwl3945_rs_sta *rs_sta,
/* Tag this window as having been updated */ /* Tag this window as having been updated */
window->stamp = jiffies; window->stamp = jiffies;
spin_unlock_irqrestore(&rs_sta->lock, flags);
} }
fail_count = window->counter - window->success_counter;
if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) ||
(window->success_counter >= IWL_RATE_MIN_SUCCESS_TH))
window->average_tpt = ((window->success_ratio *
rs_sta->expected_tpt[index] + 64) / 128);
else
window->average_tpt = IWL_INV_TPT;
spin_unlock_irqrestore(&rs_sta->lock, flags);
} }
static void rs_rate_init(void *priv, struct ieee80211_supported_band *sband, static void rs_rate_init(void *priv, struct ieee80211_supported_band *sband,
...@@ -429,19 +444,16 @@ static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband ...@@ -429,19 +444,16 @@ static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband
struct ieee80211_sta *sta, void *priv_sta, struct ieee80211_sta *sta, void *priv_sta,
struct sk_buff *skb) struct sk_buff *skb)
{ {
u8 retries = 0, current_count; s8 retries = 0, current_count;
int scale_rate_index, first_index, last_index; int scale_rate_index, first_index, last_index;
unsigned long flags; unsigned long flags;
struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_rate; struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_rate;
struct iwl3945_rs_sta *rs_sta = priv_sta; struct iwl3945_rs_sta *rs_sta = priv_sta;
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
int i;
IWL_DEBUG_RATE("enter\n"); IWL_DEBUG_RATE("enter\n");
for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) retries = info->status.rates[0].count;
retries += info->status.rates[i].count;
retries--;
first_index = sband->bitrates[info->status.rates[0].idx].hw_value; first_index = sband->bitrates[info->status.rates[0].idx].hw_value;
if ((first_index < 0) || (first_index >= IWL_RATE_COUNT)) { if ((first_index < 0) || (first_index >= IWL_RATE_COUNT)) {
...@@ -469,9 +481,9 @@ static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband ...@@ -469,9 +481,9 @@ static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband
* at which the frame was finally transmitted (or failed if no * at which the frame was finally transmitted (or failed if no
* ACK) * ACK)
*/ */
while (retries > 0) { while (retries > 1) {
if (retries < priv->retry_rate) { if ((retries - 1) < priv->retry_rate) {
current_count = retries; current_count = (retries - 1);
last_index = scale_rate_index; last_index = scale_rate_index;
} else { } else {
current_count = priv->retry_rate; current_count = priv->retry_rate;
...@@ -483,15 +495,13 @@ static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband ...@@ -483,15 +495,13 @@ static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband
* as was used for it (per current_count) */ * as was used for it (per current_count) */
iwl3945_collect_tx_data(rs_sta, iwl3945_collect_tx_data(rs_sta,
&rs_sta->win[scale_rate_index], &rs_sta->win[scale_rate_index],
0, current_count); 0, current_count, scale_rate_index);
IWL_DEBUG_RATE("Update rate %d for %d retries.\n", IWL_DEBUG_RATE("Update rate %d for %d retries.\n",
scale_rate_index, current_count); scale_rate_index, current_count);
retries -= current_count; retries -= current_count;
if (retries) scale_rate_index = last_index;
scale_rate_index =
iwl3945_rs_next_rate(priv, scale_rate_index);
} }
...@@ -502,7 +512,7 @@ static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband ...@@ -502,7 +512,7 @@ static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband
"success" : "failure"); "success" : "failure");
iwl3945_collect_tx_data(rs_sta, iwl3945_collect_tx_data(rs_sta,
&rs_sta->win[last_index], &rs_sta->win[last_index],
info->flags & IEEE80211_TX_STAT_ACK, 1); info->flags & IEEE80211_TX_STAT_ACK, 1, last_index);
/* We updated the rate scale window -- if its been more than /* We updated the rate scale window -- if its been more than
* flush_time since the last run, schedule the flush * flush_time since the last run, schedule the flush
...@@ -510,9 +520,10 @@ static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband ...@@ -510,9 +520,10 @@ static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband
spin_lock_irqsave(&rs_sta->lock, flags); spin_lock_irqsave(&rs_sta->lock, flags);
if (!rs_sta->flush_pending && if (!rs_sta->flush_pending &&
time_after(jiffies, rs_sta->last_partial_flush + time_after(jiffies, rs_sta->last_flush +
rs_sta->flush_time)) { rs_sta->flush_time)) {
rs_sta->last_partial_flush = jiffies;
rs_sta->flush_pending = 1; rs_sta->flush_pending = 1;
mod_timer(&rs_sta->rate_scale_flush, mod_timer(&rs_sta->rate_scale_flush,
jiffies + rs_sta->flush_time); jiffies + rs_sta->flush_time);
...@@ -660,7 +671,12 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, ...@@ -660,7 +671,12 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
spin_lock_irqsave(&rs_sta->lock, flags); spin_lock_irqsave(&rs_sta->lock, flags);
/* for recent assoc, choose best rate regarding
* to rssi value
*/
if (rs_sta->start_rate != IWL_RATE_INVALID) { if (rs_sta->start_rate != IWL_RATE_INVALID) {
if (rs_sta->start_rate < index &&
(rate_mask & (1 << rs_sta->start_rate)))
index = rs_sta->start_rate; index = rs_sta->start_rate;
rs_sta->start_rate = IWL_RATE_INVALID; rs_sta->start_rate = IWL_RATE_INVALID;
} }
...@@ -671,7 +687,6 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, ...@@ -671,7 +687,6 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
if (((fail_count <= IWL_RATE_MIN_FAILURE_TH) && if (((fail_count <= IWL_RATE_MIN_FAILURE_TH) &&
(window->success_counter < IWL_RATE_MIN_SUCCESS_TH))) { (window->success_counter < IWL_RATE_MIN_SUCCESS_TH))) {
window->average_tpt = IWL_INV_TPT;
spin_unlock_irqrestore(&rs_sta->lock, flags); spin_unlock_irqrestore(&rs_sta->lock, flags);
IWL_DEBUG_RATE("Invalid average_tpt on rate %d: " IWL_DEBUG_RATE("Invalid average_tpt on rate %d: "
...@@ -685,8 +700,6 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, ...@@ -685,8 +700,6 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
} }
window->average_tpt = ((window->success_ratio *
rs_sta->expected_tpt[index] + 64) / 128);
current_tpt = window->average_tpt; current_tpt = window->average_tpt;
high_low = iwl3945_get_adjacent_rate(rs_sta, index, rate_mask, high_low = iwl3945_get_adjacent_rate(rs_sta, index, rate_mask,
...@@ -734,14 +747,16 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, ...@@ -734,14 +747,16 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
} }
} }
if ((window->success_ratio > IWL_RATE_HIGH_TH) || if (scale_action == -1) {
(current_tpt > window->average_tpt)) { if (window->success_ratio > IWL_SUCCESS_DOWN_TH)
IWL_DEBUG_RATE("No action -- success_ratio [%d] > HIGH_TH or " scale_action = 0;
"current_tpt [%d] > average_tpt [%d]\n", } else if (scale_action == 1) {
window->success_ratio, if (window->success_ratio < IWL_SUCCESS_UP_TH) {
current_tpt, window->average_tpt); IWL_DEBUG_RATE("No action -- success_ratio [%d] < "
"SUCCESS UP\n", window->success_ratio);
scale_action = 0; scale_action = 0;
} }
}
switch (scale_action) { switch (scale_action) {
case -1: case -1:
......
...@@ -337,7 +337,7 @@ static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv, ...@@ -337,7 +337,7 @@ static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv,
struct iwl3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; struct iwl3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
u32 status = le32_to_cpu(tx_resp->status); u32 status = le32_to_cpu(tx_resp->status);
int rate_idx; int rate_idx;
int fail, i; int fail;
if ((index >= txq->q.n_bd) || (iwl3945_x2_queue_used(&txq->q, index) == 0)) { if ((index >= txq->q.n_bd) || (iwl3945_x2_queue_used(&txq->q, index) == 0)) {
IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
...@@ -356,27 +356,9 @@ static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv, ...@@ -356,27 +356,9 @@ static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv,
rate_idx -= IWL_FIRST_OFDM_RATE; rate_idx -= IWL_FIRST_OFDM_RATE;
fail = tx_resp->failure_frame; fail = tx_resp->failure_frame;
for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
int next = iwl3945_rs_next_rate(priv, rate_idx);
info->status.rates[i].idx = rate_idx; info->status.rates[0].idx = rate_idx;
info->status.rates[0].count = fail + 1; /* add final attempt */
/*
* Put remaining into the last count as best approximation
* of saying exactly what the hardware would have done...
*/
if ((rate_idx == next) || (i == IEEE80211_TX_MAX_RATES - 1)) {
info->status.rates[i].count = fail;
break;
}
info->status.rates[i].count = priv->retry_rate;
fail -= priv->retry_rate;
rate_idx = next;
if (fail <= 0)
break;
}
info->status.rates[i].count++; /* add final attempt */
/* tx_status->rts_retry_count = tx_resp->failure_rts; */ /* tx_status->rts_retry_count = tx_resp->failure_rts; */
info->flags |= ((status & TX_STATUS_MSK) == TX_STATUS_SUCCESS) ? info->flags |= ((status & TX_STATUS_MSK) == TX_STATUS_SUCCESS) ?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment