/** * il3945_rate_scale_flush_wins - flush out the rate scale wins * * Returns the number of wins that have gathered data but were * not flushed. If there were any that were not flushed, then * reschedule the rate flushing routine. */ static int il3945_rate_scale_flush_wins(struct il3945_rs_sta *rs_sta) { int unflushed = 0; int i; unsigned long flags; struct il_priv *il __maybe_unused = rs_sta->il; /* * For each rate, if we have collected data on that rate * and it has been more than RATE_WIN_FLUSH * since we flushed, clear out the gathered stats */ for (i = 0; i < RATE_COUNT_3945; i++) { if (!rs_sta->win[i].counter) continue; spin_lock_irqsave(&rs_sta->lock, flags); if (time_after(jiffies, rs_sta->win[i].stamp + RATE_WIN_FLUSH)) { D_RATE("flushing %d samples of rate " "idx %d\n", rs_sta->win[i].counter, i); il3945_clear_win(&rs_sta->win[i]); } else unflushed++; spin_unlock_irqrestore(&rs_sta->lock, flags); } return unflushed; }
static void * il3945_rs_alloc_sta(void *il_priv, struct ieee80211_sta *sta, gfp_t gfp) { struct il3945_rs_sta *rs_sta; struct il3945_sta_priv *psta = (void *)sta->drv_priv; struct il_priv *il __maybe_unused = il_priv; D_RATE("enter\n"); rs_sta = &psta->rs_sta; spin_lock_init(&rs_sta->lock); init_timer(&rs_sta->rate_scale_flush); D_RATE("leave\n"); return rs_sta; }
/** * il3945_hw_build_tx_cmd_rate - Add rate portion to TX_CMD: * */ void il3945_hw_build_tx_cmd_rate(struct il_priv *il, struct il_device_cmd *cmd, struct ieee80211_tx_info *info, struct ieee80211_hdr *hdr, int sta_id) { u16 hw_value = ieee80211_get_tx_rate(il->hw, info)->hw_value; u16 rate_idx = min(hw_value & 0xffff, RATE_COUNT_3945 - 1); u16 rate_mask; int rate; const u8 rts_retry_limit = 7; u8 data_retry_limit; __le32 tx_flags; __le16 fc = hdr->frame_control; struct il3945_tx_cmd *tx_cmd = (struct il3945_tx_cmd *)cmd->cmd.payload; rate = il3945_rates[rate_idx].plcp; tx_flags = tx_cmd->tx_flags; /* We need to figure out how to get the sta->supp_rates while * in this running context */ rate_mask = RATES_MASK_3945; /* Set retry limit on DATA packets and Probe Responses */ if (ieee80211_is_probe_resp(fc)) data_retry_limit = 3; else data_retry_limit = IL_DEFAULT_TX_RETRY; tx_cmd->data_retry_limit = data_retry_limit; /* Set retry limit on RTS packets */ tx_cmd->rts_retry_limit = min(data_retry_limit, rts_retry_limit); tx_cmd->rate = rate; tx_cmd->tx_flags = tx_flags; /* OFDM */ tx_cmd->supp_rates[0] = ((rate_mask & IL_OFDM_RATES_MASK) >> IL_FIRST_OFDM_RATE) & 0xFF; /* CCK */ tx_cmd->supp_rates[1] = (rate_mask & 0xF); D_RATE("Tx sta id: %d, rate: %d (plcp), flags: 0x%4X " "cck/ofdm mask: 0x%x/0x%x\n", sta_id, tx_cmd->rate, le32_to_cpu(tx_cmd->tx_flags), tx_cmd->supp_rates[1], tx_cmd->supp_rates[0]); }
static u8 il3945_sync_sta(struct il_priv *il, int sta_id, u16 tx_rate) { unsigned long flags_spin; struct il_station_entry *station; if (sta_id == IL_INVALID_STATION) return IL_INVALID_STATION; spin_lock_irqsave(&il->sta_lock, flags_spin); station = &il->stations[sta_id]; station->sta.sta.modify_mask = STA_MODIFY_TX_RATE_MSK; station->sta.rate_n_flags = cpu_to_le16(tx_rate); station->sta.mode = STA_CONTROL_MODIFY_MSK; il_send_add_sta(il, &station->sta, CMD_ASYNC); spin_unlock_irqrestore(&il->sta_lock, flags_spin); D_RATE("SCALE sync station %d to rate %d\n", sta_id, tx_rate); return sta_id; }
/** * il3945_rs_tx_status - Update rate control values based on Tx results * * NOTE: Uses il_priv->retry_rate for the # of retries attempted by * the hardware for each rate. */ static void il3945_rs_tx_status(void *il_rate, struct ieee80211_supported_band *sband, struct ieee80211_sta *sta, void *il_sta, struct sk_buff *skb) { s8 retries = 0, current_count; int scale_rate_idx, first_idx, last_idx; unsigned long flags; struct il_priv *il = (struct il_priv *)il_rate; struct il3945_rs_sta *rs_sta = il_sta; struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); D_RATE("enter\n"); retries = info->status.rates[0].count; /* Sanity Check for retries */ if (retries > RATE_RETRY_TH) retries = RATE_RETRY_TH; first_idx = sband->bitrates[info->status.rates[0].idx].hw_value; if (first_idx < 0 || first_idx >= RATE_COUNT_3945) { D_RATE("leave: Rate out of bounds: %d\n", first_idx); return; } if (!il_sta) { D_RATE("leave: No STA il data to update!\n"); return; } /* Treat uninitialized rate scaling data same as non-existing. */ if (!rs_sta->il) { D_RATE("leave: STA il data uninitialized!\n"); return; } rs_sta->tx_packets++; scale_rate_idx = first_idx; last_idx = first_idx; /* * Update the win for each rate. We determine which rates * were Tx'd based on the total number of retries vs. the number * of retries configured for each rate -- currently set to the * il value 'retry_rate' vs. rate specific * * On exit from this while loop last_idx indicates the rate * at which the frame was finally transmitted (or failed if no * ACK) */ while (retries > 1) { if ((retries - 1) < il->retry_rate) { current_count = (retries - 1); last_idx = scale_rate_idx; } else { current_count = il->retry_rate; last_idx = il3945_rs_next_rate(il, scale_rate_idx); } /* Update this rate accounting for as many retries * as was used for it (per current_count) */ il3945_collect_tx_data(rs_sta, &rs_sta->win[scale_rate_idx], 0, current_count, scale_rate_idx); D_RATE("Update rate %d for %d retries.\n", scale_rate_idx, current_count); retries -= current_count; scale_rate_idx = last_idx; } /* Update the last idx win with success/failure based on ACK */ D_RATE("Update rate %d with %s.\n", last_idx, (info->flags & IEEE80211_TX_STAT_ACK) ? "success" : "failure"); il3945_collect_tx_data(rs_sta, &rs_sta->win[last_idx], info->flags & IEEE80211_TX_STAT_ACK, 1, last_idx); /* We updated the rate scale win -- if its been more than * flush_time since the last run, schedule the flush * again */ spin_lock_irqsave(&rs_sta->lock, flags); if (!rs_sta->flush_pending && time_after(jiffies, rs_sta->last_flush + rs_sta->flush_time)) { rs_sta->last_partial_flush = jiffies; rs_sta->flush_pending = 1; mod_timer(&rs_sta->rate_scale_flush, jiffies + rs_sta->flush_time); } spin_unlock_irqrestore(&rs_sta->lock, flags); D_RATE("leave\n"); }
/** * il3945_collect_tx_data - Update the success/failure sliding win * * We keep a sliding win of the last 64 packets transmitted * at this rate. win->data contains the bitmask of successful * packets. */ static void il3945_collect_tx_data(struct il3945_rs_sta *rs_sta, struct il3945_rate_scale_data *win, int success, int retries, int idx) { unsigned long flags; s32 fail_count; struct il_priv *il __maybe_unused = rs_sta->il; if (!retries) { D_RATE("leave: retries == 0 -- should be at least 1\n"); return; } spin_lock_irqsave(&rs_sta->lock, flags); /* * Keep track of only the latest 62 tx frame attempts in this rate's * history win; anything older isn't really relevant any more. * If we have filled up the sliding win, 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 (retries > 0) { if (win->counter >= RATE_MAX_WINDOW) { /* remove earliest */ win->counter = RATE_MAX_WINDOW - 1; if (win->data & (1ULL << (RATE_MAX_WINDOW - 1))) { win->data &= ~(1ULL << (RATE_MAX_WINDOW - 1)); win->success_counter--; } } /* Increment frames-attempted counter */ win->counter++; /* Shift bitmap by one frame (throw away oldest history), * OR in "1", and increment "success" if this * frame was successful. */ win->data <<= 1; if (success > 0) { win->success_counter++; win->data |= 0x1; success--; } retries--; } /* Calculate current success ratio, avoid divide-by-0! */ if (win->counter > 0) win->success_ratio = 128 * (100 * win->success_counter) / win->counter; else win->success_ratio = IL_INVALID_VALUE; fail_count = win->counter - win->success_counter; /* Calculate average throughput, if we have enough history. */ if (fail_count >= RATE_MIN_FAILURE_TH || win->success_counter >= RATE_MIN_SUCCESS_TH) win->average_tpt = ((win->success_ratio * rs_sta->expected_tpt[idx] + 64) / 128); else win->average_tpt = IL_INVALID_VALUE; /* Tag this win as having been updated */ win->stamp = jiffies; spin_unlock_irqrestore(&rs_sta->lock, flags); }
static void il3945_bg_rate_scale_flush(unsigned long data) { struct il3945_rs_sta *rs_sta = (void *)data; struct il_priv *il __maybe_unused = rs_sta->il; int unflushed = 0; unsigned long flags; u32 packet_count, duration, pps; D_RATE("enter\n"); unflushed = il3945_rate_scale_flush_wins(rs_sta); spin_lock_irqsave(&rs_sta->lock, flags); /* Number of packets Rx'd since last time this timer ran */ packet_count = (rs_sta->tx_packets - rs_sta->last_tx_packets) + 1; rs_sta->last_tx_packets = rs_sta->tx_packets + 1; if (unflushed) { duration = jiffies_to_msecs(jiffies - rs_sta->last_partial_flush); D_RATE("Tx'd %d packets in %dms\n", packet_count, duration); /* Determine packets per second */ if (duration) pps = (packet_count * 1000) / duration; else pps = 0; if (pps) { duration = (IL_AVERAGE_PACKETS * 1000) / pps; if (duration < RATE_FLUSH_MIN) duration = RATE_FLUSH_MIN; else if (duration > RATE_FLUSH_MAX) duration = RATE_FLUSH_MAX; } else duration = RATE_FLUSH_MAX; rs_sta->flush_time = msecs_to_jiffies(duration); D_RATE("new flush period: %d msec ave %d\n", duration, packet_count); mod_timer(&rs_sta->rate_scale_flush, jiffies + rs_sta->flush_time); rs_sta->last_partial_flush = jiffies; } else { rs_sta->flush_time = RATE_FLUSH; rs_sta->flush_pending = 0; } /* If there weren't any unflushed entries, we don't schedule the timer * to run again */ rs_sta->last_flush = jiffies; spin_unlock_irqrestore(&rs_sta->lock, flags); D_RATE("leave\n"); }