2008-10-05 20:07:45 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Based on minstrel.c:
|
|
|
|
* Copyright (C) 2005-2007 Derek Smithies <derek@indranet.co.nz>
|
|
|
|
* Sponsored by Indranet Technologies Ltd
|
|
|
|
*
|
|
|
|
* Based on sample.c:
|
|
|
|
* Copyright (c) 2005 John Bicket
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer,
|
|
|
|
* without modification.
|
|
|
|
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
|
|
|
|
* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
|
|
|
|
* redistribution must be conditioned upon including a substantially
|
|
|
|
* similar Disclaimer requirement for further binary redistribution.
|
|
|
|
* 3. Neither the names of the above-listed copyright holders nor the names
|
|
|
|
* of any contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* Alternatively, this software may be distributed under the terms of the
|
|
|
|
* GNU General Public License ("GPL") version 2 as published by the Free
|
|
|
|
* Software Foundation.
|
|
|
|
*
|
|
|
|
* NO WARRANTY
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
|
|
|
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
|
|
|
|
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
|
|
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGES.
|
|
|
|
*/
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/debugfs.h>
|
|
|
|
#include <linux/random.h>
|
|
|
|
#include <linux/ieee80211.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2008-10-05 20:07:45 +04:00
|
|
|
#include <net/mac80211.h>
|
|
|
|
#include "rate.h"
|
|
|
|
#include "rc80211_minstrel.h"
|
|
|
|
|
|
|
|
#define SAMPLE_TBL(_mi, _idx, _col) \
|
|
|
|
_mi->sample_table[(_idx * SAMPLE_COLUMNS) + _col]
|
|
|
|
|
|
|
|
/* convert mac80211 rate index to local array index */
|
|
|
|
static inline int
|
|
|
|
rix_to_ndx(struct minstrel_sta_info *mi, int rix)
|
|
|
|
{
|
|
|
|
int i = rix;
|
|
|
|
for (i = rix; i >= 0; i--)
|
|
|
|
if (mi->r[i].rix == rix)
|
|
|
|
break;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2013-03-05 02:30:07 +04:00
|
|
|
/* find & sort topmost throughput rates */
|
|
|
|
static inline void
|
|
|
|
minstrel_sort_best_tp_rates(struct minstrel_sta_info *mi, int i, u8 *tp_list)
|
|
|
|
{
|
|
|
|
int j = MAX_THR_RATES;
|
|
|
|
|
|
|
|
while (j > 0 && mi->r[i].cur_tp > mi->r[tp_list[j - 1]].cur_tp)
|
|
|
|
j--;
|
|
|
|
if (j < MAX_THR_RATES - 1)
|
|
|
|
memmove(&tp_list[j + 1], &tp_list[j], MAX_THR_RATES - (j + 1));
|
|
|
|
if (j < MAX_THR_RATES)
|
|
|
|
tp_list[j] = i;
|
|
|
|
}
|
|
|
|
|
2013-04-22 18:14:43 +04:00
|
|
|
static void
|
|
|
|
minstrel_set_rate(struct minstrel_sta_info *mi, struct ieee80211_sta_rates *ratetbl,
|
|
|
|
int offset, int idx)
|
|
|
|
{
|
|
|
|
struct minstrel_rate *r = &mi->r[idx];
|
|
|
|
|
|
|
|
ratetbl->rate[offset].idx = r->rix;
|
|
|
|
ratetbl->rate[offset].count = r->adjusted_retry_count;
|
|
|
|
ratetbl->rate[offset].count_cts = r->retry_count_cts;
|
|
|
|
ratetbl->rate[offset].count_rts = r->retry_count_rtscts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
minstrel_update_rates(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
|
|
|
|
{
|
|
|
|
struct ieee80211_sta_rates *ratetbl;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
ratetbl = kzalloc(sizeof(*ratetbl), GFP_ATOMIC);
|
|
|
|
if (!ratetbl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Start with max_tp_rate */
|
|
|
|
minstrel_set_rate(mi, ratetbl, i++, mi->max_tp_rate[0]);
|
|
|
|
|
|
|
|
if (mp->hw->max_rates >= 3) {
|
|
|
|
/* At least 3 tx rates supported, use max_tp_rate2 next */
|
|
|
|
minstrel_set_rate(mi, ratetbl, i++, mi->max_tp_rate[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mp->hw->max_rates >= 2) {
|
|
|
|
/* At least 2 tx rates supported, use max_prob_rate next */
|
|
|
|
minstrel_set_rate(mi, ratetbl, i++, mi->max_prob_rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use lowest rate last */
|
|
|
|
ratetbl->rate[i].idx = mi->lowest_rix;
|
|
|
|
ratetbl->rate[i].count = mp->max_retry;
|
|
|
|
ratetbl->rate[i].count_cts = mp->max_retry;
|
|
|
|
ratetbl->rate[i].count_rts = mp->max_retry;
|
|
|
|
|
|
|
|
rate_control_set_rates(mp->hw, mi->sta, ratetbl);
|
|
|
|
}
|
|
|
|
|
2008-10-05 20:07:45 +04:00
|
|
|
static void
|
|
|
|
minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
|
|
|
|
{
|
2013-03-05 02:30:07 +04:00
|
|
|
u8 tmp_tp_rate[MAX_THR_RATES];
|
|
|
|
u8 tmp_prob_rate = 0;
|
2008-10-05 20:07:45 +04:00
|
|
|
u32 usecs;
|
|
|
|
int i;
|
|
|
|
|
2013-03-05 02:30:07 +04:00
|
|
|
for (i=0; i < MAX_THR_RATES; i++)
|
|
|
|
tmp_tp_rate[i] = 0;
|
|
|
|
|
2008-10-05 20:07:45 +04:00
|
|
|
for (i = 0; i < mi->n_rates; i++) {
|
|
|
|
struct minstrel_rate *mr = &mi->r[i];
|
|
|
|
|
|
|
|
usecs = mr->perfect_tx_time;
|
|
|
|
if (!usecs)
|
|
|
|
usecs = 1000000;
|
|
|
|
|
2013-03-05 02:30:04 +04:00
|
|
|
if (unlikely(mr->attempts > 0)) {
|
|
|
|
mr->sample_skipped = 0;
|
2013-03-05 02:30:02 +04:00
|
|
|
mr->cur_prob = MINSTREL_FRAC(mr->success, mr->attempts);
|
2008-10-05 20:07:45 +04:00
|
|
|
mr->succ_hist += mr->success;
|
|
|
|
mr->att_hist += mr->attempts;
|
2013-03-05 02:30:01 +04:00
|
|
|
mr->probability = minstrel_ewma(mr->probability,
|
|
|
|
mr->cur_prob,
|
|
|
|
EWMA_LEVEL);
|
2013-03-05 02:30:04 +04:00
|
|
|
} else
|
|
|
|
mr->sample_skipped++;
|
2008-10-05 20:07:45 +04:00
|
|
|
|
|
|
|
mr->last_success = mr->success;
|
|
|
|
mr->last_attempts = mr->attempts;
|
|
|
|
mr->success = 0;
|
|
|
|
mr->attempts = 0;
|
|
|
|
|
2013-03-05 02:30:06 +04:00
|
|
|
/* Update throughput per rate, reset thr. below 10% success */
|
|
|
|
if (mr->probability < MINSTREL_FRAC(10, 100))
|
|
|
|
mr->cur_tp = 0;
|
|
|
|
else
|
|
|
|
mr->cur_tp = mr->probability * (1000000 / usecs);
|
|
|
|
|
2008-10-05 20:07:45 +04:00
|
|
|
/* Sample less often below the 10% chance of success.
|
|
|
|
* Sample less often above the 95% chance of success. */
|
2013-03-05 02:30:02 +04:00
|
|
|
if (mr->probability > MINSTREL_FRAC(95, 100) ||
|
|
|
|
mr->probability < MINSTREL_FRAC(10, 100)) {
|
2008-10-05 20:07:45 +04:00
|
|
|
mr->adjusted_retry_count = mr->retry_count >> 1;
|
|
|
|
if (mr->adjusted_retry_count > 2)
|
|
|
|
mr->adjusted_retry_count = 2;
|
2008-10-15 21:13:59 +04:00
|
|
|
mr->sample_limit = 4;
|
2008-10-05 20:07:45 +04:00
|
|
|
} else {
|
2008-10-15 21:13:59 +04:00
|
|
|
mr->sample_limit = -1;
|
2008-10-05 20:07:45 +04:00
|
|
|
mr->adjusted_retry_count = mr->retry_count;
|
|
|
|
}
|
|
|
|
if (!mr->adjusted_retry_count)
|
|
|
|
mr->adjusted_retry_count = 2;
|
|
|
|
|
2013-03-05 02:30:07 +04:00
|
|
|
minstrel_sort_best_tp_rates(mi, i, tmp_tp_rate);
|
|
|
|
|
|
|
|
/* To determine the most robust rate (max_prob_rate) used at
|
|
|
|
* 3rd mmr stage we distinct between two cases:
|
|
|
|
* (1) if any success probabilitiy >= 95%, out of those rates
|
|
|
|
* choose the maximum throughput rate as max_prob_rate
|
|
|
|
* (2) if all success probabilities < 95%, the rate with
|
|
|
|
* highest success probability is choosen as max_prob_rate */
|
|
|
|
if (mr->probability >= MINSTREL_FRAC(95,100)) {
|
|
|
|
if (mr->cur_tp >= mi->r[tmp_prob_rate].cur_tp)
|
|
|
|
tmp_prob_rate = i;
|
|
|
|
} else {
|
|
|
|
if (mr->probability >= mi->r[tmp_prob_rate].probability)
|
|
|
|
tmp_prob_rate = i;
|
2008-10-05 20:07:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-05 02:30:07 +04:00
|
|
|
/* Assign the new rate set */
|
|
|
|
memcpy(mi->max_tp_rate, tmp_tp_rate, sizeof(mi->max_tp_rate));
|
|
|
|
mi->max_prob_rate = tmp_prob_rate;
|
2013-03-05 02:30:03 +04:00
|
|
|
|
|
|
|
/* Reset update timer */
|
|
|
|
mi->stats_update = jiffies;
|
2013-04-22 18:14:43 +04:00
|
|
|
|
|
|
|
minstrel_update_rates(mp, mi);
|
2008-10-05 20:07:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
minstrel_tx_status(void *priv, struct ieee80211_supported_band *sband,
|
|
|
|
struct ieee80211_sta *sta, void *priv_sta,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
2012-11-15 21:27:56 +04:00
|
|
|
struct minstrel_priv *mp = priv;
|
2008-10-05 20:07:45 +04:00
|
|
|
struct minstrel_sta_info *mi = priv_sta;
|
|
|
|
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
|
2008-10-21 14:40:02 +04:00
|
|
|
struct ieee80211_tx_rate *ar = info->status.rates;
|
|
|
|
int i, ndx;
|
|
|
|
int success;
|
2008-10-05 20:07:45 +04:00
|
|
|
|
2008-10-21 14:40:02 +04:00
|
|
|
success = !!(info->flags & IEEE80211_TX_STAT_ACK);
|
2008-10-05 20:07:45 +04:00
|
|
|
|
2008-10-21 14:40:02 +04:00
|
|
|
for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
|
|
|
|
if (ar[i].idx < 0)
|
2008-10-05 20:07:45 +04:00
|
|
|
break;
|
|
|
|
|
2008-10-21 14:40:02 +04:00
|
|
|
ndx = rix_to_ndx(mi, ar[i].idx);
|
2009-07-03 09:25:08 +04:00
|
|
|
if (ndx < 0)
|
|
|
|
continue;
|
|
|
|
|
2008-10-21 14:40:02 +04:00
|
|
|
mi->r[ndx].attempts += ar[i].count;
|
2008-10-05 20:07:45 +04:00
|
|
|
|
2009-08-18 04:15:55 +04:00
|
|
|
if ((i != IEEE80211_TX_MAX_RATES - 1) && (ar[i + 1].idx < 0))
|
2008-10-05 20:07:45 +04:00
|
|
|
mi->r[ndx].success += success;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) && (i >= 0))
|
|
|
|
mi->sample_count++;
|
|
|
|
|
|
|
|
if (mi->sample_deferred > 0)
|
|
|
|
mi->sample_deferred--;
|
2012-11-15 21:27:56 +04:00
|
|
|
|
|
|
|
if (time_after(jiffies, mi->stats_update +
|
|
|
|
(mp->update_interval * HZ) / 1000))
|
|
|
|
minstrel_update_stats(mp, mi);
|
2008-10-05 20:07:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline unsigned int
|
|
|
|
minstrel_get_retry_count(struct minstrel_rate *mr,
|
|
|
|
struct ieee80211_tx_info *info)
|
|
|
|
{
|
|
|
|
unsigned int retry = mr->adjusted_retry_count;
|
|
|
|
|
2013-04-16 15:38:43 +04:00
|
|
|
if (info->control.use_rts)
|
2008-10-05 20:07:45 +04:00
|
|
|
retry = max(2U, min(mr->retry_count_rtscts, retry));
|
2013-04-16 15:38:43 +04:00
|
|
|
else if (info->control.use_cts_prot)
|
2008-10-05 20:07:45 +04:00
|
|
|
retry = max(2U, min(mr->retry_count_cts, retry));
|
|
|
|
return retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
minstrel_get_next_sample(struct minstrel_sta_info *mi)
|
|
|
|
{
|
|
|
|
unsigned int sample_ndx;
|
2013-03-05 02:30:03 +04:00
|
|
|
sample_ndx = SAMPLE_TBL(mi, mi->sample_row, mi->sample_column);
|
|
|
|
mi->sample_row++;
|
2013-03-05 02:30:05 +04:00
|
|
|
if ((int) mi->sample_row >= mi->n_rates) {
|
2013-03-05 02:30:03 +04:00
|
|
|
mi->sample_row = 0;
|
2008-10-05 20:07:45 +04:00
|
|
|
mi->sample_column++;
|
|
|
|
if (mi->sample_column >= SAMPLE_COLUMNS)
|
|
|
|
mi->sample_column = 0;
|
|
|
|
}
|
|
|
|
return sample_ndx;
|
|
|
|
}
|
|
|
|
|
2008-10-28 18:49:41 +03:00
|
|
|
static void
|
2008-10-21 14:40:02 +04:00
|
|
|
minstrel_get_rate(void *priv, struct ieee80211_sta *sta,
|
|
|
|
void *priv_sta, struct ieee80211_tx_rate_control *txrc)
|
2008-10-05 20:07:45 +04:00
|
|
|
{
|
2008-10-21 14:40:02 +04:00
|
|
|
struct sk_buff *skb = txrc->skb;
|
2008-10-05 20:07:45 +04:00
|
|
|
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
|
|
|
|
struct minstrel_sta_info *mi = priv_sta;
|
|
|
|
struct minstrel_priv *mp = priv;
|
2013-04-22 18:14:43 +04:00
|
|
|
struct ieee80211_tx_rate *rate = &info->control.rates[0];
|
|
|
|
struct minstrel_rate *msr, *mr;
|
|
|
|
unsigned int ndx;
|
2013-03-05 02:30:03 +04:00
|
|
|
bool mrr_capable;
|
2013-04-22 18:14:43 +04:00
|
|
|
bool prev_sample = mi->prev_sample;
|
|
|
|
int delta;
|
2013-03-05 02:30:03 +04:00
|
|
|
int sampling_ratio;
|
2008-10-05 20:07:45 +04:00
|
|
|
|
2013-03-05 02:30:03 +04:00
|
|
|
/* management/no-ack frames do not use rate control */
|
2009-07-16 21:05:41 +04:00
|
|
|
if (rate_control_send_low(sta, priv_sta, txrc))
|
2008-10-05 20:07:45 +04:00
|
|
|
return;
|
|
|
|
|
2013-03-05 02:30:03 +04:00
|
|
|
/* check multi-rate-retry capabilities & adjust lookaround_rate */
|
|
|
|
mrr_capable = mp->has_mrr &&
|
|
|
|
!txrc->rts &&
|
|
|
|
!txrc->bss_conf->use_cts_prot;
|
|
|
|
if (mrr_capable)
|
|
|
|
sampling_ratio = mp->lookaround_rate_mrr;
|
|
|
|
else
|
|
|
|
sampling_ratio = mp->lookaround_rate;
|
2008-10-05 20:07:45 +04:00
|
|
|
|
2013-03-05 02:30:03 +04:00
|
|
|
/* increase sum packet counter */
|
2008-10-05 20:07:45 +04:00
|
|
|
mi->packet_count++;
|
2013-03-05 02:30:03 +04:00
|
|
|
|
|
|
|
delta = (mi->packet_count * sampling_ratio / 100) -
|
2008-10-05 20:07:45 +04:00
|
|
|
(mi->sample_count + mi->sample_deferred / 2);
|
|
|
|
|
2013-04-22 18:14:43 +04:00
|
|
|
/* delta < 0: no sampling required */
|
|
|
|
mi->prev_sample = false;
|
|
|
|
if (delta < 0 || (!mrr_capable && prev_sample))
|
|
|
|
return;
|
2008-10-05 20:07:45 +04:00
|
|
|
|
2013-04-22 18:14:43 +04:00
|
|
|
if (mi->packet_count >= 10000) {
|
|
|
|
mi->sample_deferred = 0;
|
|
|
|
mi->sample_count = 0;
|
|
|
|
mi->packet_count = 0;
|
|
|
|
} else if (delta > mi->n_rates * 2) {
|
|
|
|
/* With multi-rate retry, not every planned sample
|
|
|
|
* attempt actually gets used, due to the way the retry
|
|
|
|
* chain is set up - [max_tp,sample,prob,lowest] for
|
|
|
|
* sample_rate < max_tp.
|
|
|
|
*
|
|
|
|
* If there's too much sampling backlog and the link
|
|
|
|
* starts getting worse, minstrel would start bursting
|
|
|
|
* out lots of sampling frames, which would result
|
|
|
|
* in a large throughput loss. */
|
|
|
|
mi->sample_count += (delta - mi->n_rates * 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get next random rate sample */
|
|
|
|
ndx = minstrel_get_next_sample(mi);
|
|
|
|
msr = &mi->r[ndx];
|
|
|
|
mr = &mi->r[mi->max_tp_rate[0]];
|
|
|
|
|
|
|
|
/* Decide if direct ( 1st mrr stage) or indirect (2nd mrr stage)
|
|
|
|
* rate sampling method should be used.
|
|
|
|
* Respect such rates that are not sampled for 20 interations.
|
|
|
|
*/
|
|
|
|
if (mrr_capable &&
|
|
|
|
msr->perfect_tx_time > mr->perfect_tx_time &&
|
|
|
|
msr->sample_skipped < 20) {
|
|
|
|
/* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark
|
|
|
|
* packets that have the sampling rate deferred to the
|
|
|
|
* second MRR stage. Increase the sample counter only
|
|
|
|
* if the deferred sample rate was actually used.
|
|
|
|
* Use the sample_deferred counter to make sure that
|
|
|
|
* the sampling is not done in large bursts */
|
|
|
|
info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
|
|
|
|
rate++;
|
|
|
|
mi->sample_deferred++;
|
|
|
|
} else {
|
|
|
|
if (!msr->sample_limit != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mi->sample_count++;
|
|
|
|
if (msr->sample_limit > 0)
|
|
|
|
msr->sample_limit--;
|
2008-10-05 20:07:45 +04:00
|
|
|
}
|
2008-10-15 21:13:59 +04:00
|
|
|
|
|
|
|
/* If we're not using MRR and the sampling rate already
|
|
|
|
* has a probability of >95%, we shouldn't be attempting
|
|
|
|
* to use it, as this only wastes precious airtime */
|
2013-04-22 18:14:43 +04:00
|
|
|
if (!mrr_capable &&
|
2013-03-05 02:30:03 +04:00
|
|
|
(mi->r[ndx].probability > MINSTREL_FRAC(95, 100)))
|
2008-10-05 20:07:45 +04:00
|
|
|
return;
|
|
|
|
|
2013-04-22 18:14:43 +04:00
|
|
|
mi->prev_sample = true;
|
2013-03-05 02:30:03 +04:00
|
|
|
|
2013-04-22 18:14:43 +04:00
|
|
|
rate->idx = mi->r[ndx].rix;
|
|
|
|
rate->count = minstrel_get_retry_count(&mi->r[ndx], info);
|
2008-10-05 20:07:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2012-04-11 10:47:56 +04:00
|
|
|
calc_rate_durations(enum ieee80211_band band,
|
|
|
|
struct minstrel_rate *d,
|
2011-11-10 18:13:11 +04:00
|
|
|
struct ieee80211_rate *rate)
|
2008-10-05 20:07:45 +04:00
|
|
|
{
|
|
|
|
int erp = !!(rate->flags & IEEE80211_RATE_ERP_G);
|
|
|
|
|
2012-04-11 10:47:56 +04:00
|
|
|
d->perfect_tx_time = ieee80211_frame_duration(band, 1200,
|
2008-10-05 20:07:45 +04:00
|
|
|
rate->bitrate, erp, 1);
|
2012-04-11 10:47:56 +04:00
|
|
|
d->ack_time = ieee80211_frame_duration(band, 10,
|
2008-10-05 20:07:45 +04:00
|
|
|
rate->bitrate, erp, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_sample_table(struct minstrel_sta_info *mi)
|
|
|
|
{
|
|
|
|
unsigned int i, col, new_idx;
|
|
|
|
u8 rnd[8];
|
|
|
|
|
|
|
|
mi->sample_column = 0;
|
2013-03-05 02:30:03 +04:00
|
|
|
mi->sample_row = 0;
|
2013-03-05 02:30:05 +04:00
|
|
|
memset(mi->sample_table, 0xff, SAMPLE_COLUMNS * mi->n_rates);
|
2008-10-05 20:07:45 +04:00
|
|
|
|
|
|
|
for (col = 0; col < SAMPLE_COLUMNS; col++) {
|
2013-03-05 02:30:05 +04:00
|
|
|
for (i = 0; i < mi->n_rates; i++) {
|
2008-10-05 20:07:45 +04:00
|
|
|
get_random_bytes(rnd, sizeof(rnd));
|
2013-03-05 02:30:05 +04:00
|
|
|
new_idx = (i + rnd[i & 7]) % mi->n_rates;
|
2008-10-05 20:07:45 +04:00
|
|
|
|
2013-03-05 02:30:05 +04:00
|
|
|
while (SAMPLE_TBL(mi, new_idx, col) != 0xff)
|
|
|
|
new_idx = (new_idx + 1) % mi->n_rates;
|
2008-10-05 20:07:45 +04:00
|
|
|
|
2013-03-05 02:30:05 +04:00
|
|
|
SAMPLE_TBL(mi, new_idx, col) = i;
|
2008-10-05 20:07:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
minstrel_rate_init(void *priv, struct ieee80211_supported_band *sband,
|
|
|
|
struct ieee80211_sta *sta, void *priv_sta)
|
|
|
|
{
|
|
|
|
struct minstrel_sta_info *mi = priv_sta;
|
|
|
|
struct minstrel_priv *mp = priv;
|
2008-12-22 17:35:31 +03:00
|
|
|
struct ieee80211_rate *ctl_rate;
|
2008-10-05 20:07:45 +04:00
|
|
|
unsigned int i, n = 0;
|
|
|
|
unsigned int t_slot = 9; /* FIXME: get real slot time */
|
|
|
|
|
2013-04-22 18:14:43 +04:00
|
|
|
mi->sta = sta;
|
2008-10-05 20:07:45 +04:00
|
|
|
mi->lowest_rix = rate_lowest_index(sband, sta);
|
2008-12-22 17:35:31 +03:00
|
|
|
ctl_rate = &sband->bitrates[mi->lowest_rix];
|
2012-04-11 10:47:56 +04:00
|
|
|
mi->sp_ack_dur = ieee80211_frame_duration(sband->band, 10,
|
|
|
|
ctl_rate->bitrate,
|
2008-12-22 17:35:31 +03:00
|
|
|
!!(ctl_rate->flags & IEEE80211_RATE_ERP_G), 1);
|
2008-10-05 20:07:45 +04:00
|
|
|
|
2013-04-22 18:14:43 +04:00
|
|
|
memset(mi->max_tp_rate, 0, sizeof(mi->max_tp_rate));
|
|
|
|
mi->max_prob_rate = 0;
|
|
|
|
|
2008-10-05 20:07:45 +04:00
|
|
|
for (i = 0; i < sband->n_bitrates; i++) {
|
|
|
|
struct minstrel_rate *mr = &mi->r[n];
|
|
|
|
unsigned int tx_time = 0, tx_time_cts = 0, tx_time_rtscts = 0;
|
|
|
|
unsigned int tx_time_single;
|
|
|
|
unsigned int cw = mp->cw_min;
|
|
|
|
|
|
|
|
if (!rate_supported(sta, sband->band, i))
|
|
|
|
continue;
|
|
|
|
n++;
|
|
|
|
memset(mr, 0, sizeof(*mr));
|
|
|
|
|
|
|
|
mr->rix = i;
|
|
|
|
mr->bitrate = sband->bitrates[i].bitrate / 5;
|
2012-04-11 10:47:56 +04:00
|
|
|
calc_rate_durations(sband->band, mr, &sband->bitrates[i]);
|
2008-10-05 20:07:45 +04:00
|
|
|
|
|
|
|
/* calculate maximum number of retransmissions before
|
|
|
|
* fallback (based on maximum segment size) */
|
2008-10-15 21:13:59 +04:00
|
|
|
mr->sample_limit = -1;
|
2008-10-05 20:07:45 +04:00
|
|
|
mr->retry_count = 1;
|
|
|
|
mr->retry_count_cts = 1;
|
|
|
|
mr->retry_count_rtscts = 1;
|
|
|
|
tx_time = mr->perfect_tx_time + mi->sp_ack_dur;
|
|
|
|
do {
|
|
|
|
/* add one retransmission */
|
|
|
|
tx_time_single = mr->ack_time + mr->perfect_tx_time;
|
|
|
|
|
|
|
|
/* contention window */
|
2011-05-11 06:00:45 +04:00
|
|
|
tx_time_single += (t_slot * cw) >> 1;
|
|
|
|
cw = min((cw << 1) | 1, mp->cw_max);
|
2008-10-05 20:07:45 +04:00
|
|
|
|
|
|
|
tx_time += tx_time_single;
|
|
|
|
tx_time_cts += tx_time_single + mi->sp_ack_dur;
|
|
|
|
tx_time_rtscts += tx_time_single + 2 * mi->sp_ack_dur;
|
|
|
|
if ((tx_time_cts < mp->segment_size) &&
|
|
|
|
(mr->retry_count_cts < mp->max_retry))
|
|
|
|
mr->retry_count_cts++;
|
|
|
|
if ((tx_time_rtscts < mp->segment_size) &&
|
|
|
|
(mr->retry_count_rtscts < mp->max_retry))
|
|
|
|
mr->retry_count_rtscts++;
|
|
|
|
} while ((tx_time < mp->segment_size) &&
|
|
|
|
(++mr->retry_count < mp->max_retry));
|
|
|
|
mr->adjusted_retry_count = mr->retry_count;
|
2013-04-16 15:38:43 +04:00
|
|
|
if (!(sband->bitrates[i].flags & IEEE80211_RATE_ERP_G))
|
|
|
|
mr->retry_count_cts = mr->retry_count;
|
2008-10-05 20:07:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = n; i < sband->n_bitrates; i++) {
|
|
|
|
struct minstrel_rate *mr = &mi->r[i];
|
|
|
|
mr->rix = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mi->n_rates = n;
|
|
|
|
mi->stats_update = jiffies;
|
|
|
|
|
|
|
|
init_sample_table(mi);
|
2013-04-22 18:14:43 +04:00
|
|
|
minstrel_update_rates(mp, mi);
|
2008-10-05 20:07:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
minstrel_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
|
|
|
|
{
|
|
|
|
struct ieee80211_supported_band *sband;
|
|
|
|
struct minstrel_sta_info *mi;
|
|
|
|
struct minstrel_priv *mp = priv;
|
|
|
|
struct ieee80211_hw *hw = mp->hw;
|
|
|
|
int max_rates = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mi = kzalloc(sizeof(struct minstrel_sta_info), gfp);
|
|
|
|
if (!mi)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
|
2009-05-04 20:04:55 +04:00
|
|
|
sband = hw->wiphy->bands[i];
|
2009-05-05 23:18:26 +04:00
|
|
|
if (sband && sband->n_bitrates > max_rates)
|
2008-10-05 20:07:45 +04:00
|
|
|
max_rates = sband->n_bitrates;
|
|
|
|
}
|
|
|
|
|
|
|
|
mi->r = kzalloc(sizeof(struct minstrel_rate) * max_rates, gfp);
|
|
|
|
if (!mi->r)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
mi->sample_table = kmalloc(SAMPLE_COLUMNS * max_rates, gfp);
|
|
|
|
if (!mi->sample_table)
|
|
|
|
goto error1;
|
|
|
|
|
|
|
|
mi->stats_update = jiffies;
|
|
|
|
return mi;
|
|
|
|
|
|
|
|
error1:
|
|
|
|
kfree(mi->r);
|
|
|
|
error:
|
|
|
|
kfree(mi);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
minstrel_free_sta(void *priv, struct ieee80211_sta *sta, void *priv_sta)
|
|
|
|
{
|
|
|
|
struct minstrel_sta_info *mi = priv_sta;
|
|
|
|
|
|
|
|
kfree(mi->sample_table);
|
|
|
|
kfree(mi->r);
|
|
|
|
kfree(mi);
|
|
|
|
}
|
|
|
|
|
2013-02-13 13:51:08 +04:00
|
|
|
static void
|
|
|
|
minstrel_init_cck_rates(struct minstrel_priv *mp)
|
|
|
|
{
|
|
|
|
static const int bitrates[4] = { 10, 20, 55, 110 };
|
|
|
|
struct ieee80211_supported_band *sband;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
sband = mp->hw->wiphy->bands[IEEE80211_BAND_2GHZ];
|
|
|
|
if (!sband)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < sband->n_bitrates; i++) {
|
|
|
|
struct ieee80211_rate *rate = &sband->bitrates[i];
|
|
|
|
|
|
|
|
if (rate->flags & IEEE80211_RATE_ERP_G)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j = 0; j < ARRAY_SIZE(bitrates); j++) {
|
|
|
|
if (rate->bitrate != bitrates[j])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
mp->cck_rates[j] = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-05 20:07:45 +04:00
|
|
|
static void *
|
|
|
|
minstrel_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
|
|
|
|
{
|
|
|
|
struct minstrel_priv *mp;
|
|
|
|
|
|
|
|
mp = kzalloc(sizeof(struct minstrel_priv), GFP_ATOMIC);
|
|
|
|
if (!mp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* contention window settings
|
|
|
|
* Just an approximation. Using the per-queue values would complicate
|
|
|
|
* the calculations and is probably unnecessary */
|
|
|
|
mp->cw_min = 15;
|
|
|
|
mp->cw_max = 1023;
|
|
|
|
|
|
|
|
/* number of packets (in %) to use for sampling other rates
|
|
|
|
* sample less often for non-mrr packets, because the overhead
|
|
|
|
* is much higher than with mrr */
|
|
|
|
mp->lookaround_rate = 5;
|
|
|
|
mp->lookaround_rate_mrr = 10;
|
|
|
|
|
|
|
|
/* maximum time that the hw is allowed to stay in one MRR segment */
|
|
|
|
mp->segment_size = 6000;
|
|
|
|
|
2008-10-21 14:40:02 +04:00
|
|
|
if (hw->max_rate_tries > 0)
|
|
|
|
mp->max_retry = hw->max_rate_tries;
|
2008-10-05 20:07:45 +04:00
|
|
|
else
|
|
|
|
/* safe default, does not necessarily have to match hw properties */
|
|
|
|
mp->max_retry = 7;
|
|
|
|
|
2008-10-21 14:40:02 +04:00
|
|
|
if (hw->max_rates >= 4)
|
2008-10-05 20:07:45 +04:00
|
|
|
mp->has_mrr = true;
|
|
|
|
|
|
|
|
mp->hw = hw;
|
|
|
|
mp->update_interval = 100;
|
|
|
|
|
2011-05-20 22:29:17 +04:00
|
|
|
#ifdef CONFIG_MAC80211_DEBUGFS
|
|
|
|
mp->fixed_rate_idx = (u32) -1;
|
|
|
|
mp->dbg_fixed_rate = debugfs_create_u32("fixed_rate_idx",
|
|
|
|
S_IRUGO | S_IWUGO, debugfsdir, &mp->fixed_rate_idx);
|
|
|
|
#endif
|
|
|
|
|
2013-02-13 13:51:08 +04:00
|
|
|
minstrel_init_cck_rates(mp);
|
|
|
|
|
2008-10-05 20:07:45 +04:00
|
|
|
return mp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
minstrel_free(void *priv)
|
|
|
|
{
|
2011-05-20 22:29:17 +04:00
|
|
|
#ifdef CONFIG_MAC80211_DEBUGFS
|
|
|
|
debugfs_remove(((struct minstrel_priv *)priv)->dbg_fixed_rate);
|
|
|
|
#endif
|
2008-10-05 20:07:45 +04:00
|
|
|
kfree(priv);
|
|
|
|
}
|
|
|
|
|
2010-03-02 00:21:40 +03:00
|
|
|
struct rate_control_ops mac80211_minstrel = {
|
2008-10-05 20:07:45 +04:00
|
|
|
.name = "minstrel",
|
|
|
|
.tx_status = minstrel_tx_status,
|
|
|
|
.get_rate = minstrel_get_rate,
|
|
|
|
.rate_init = minstrel_rate_init,
|
|
|
|
.alloc = minstrel_alloc,
|
|
|
|
.free = minstrel_free,
|
|
|
|
.alloc_sta = minstrel_alloc_sta,
|
|
|
|
.free_sta = minstrel_free_sta,
|
|
|
|
#ifdef CONFIG_MAC80211_DEBUGFS
|
|
|
|
.add_sta_debugfs = minstrel_add_sta_debugfs,
|
|
|
|
.remove_sta_debugfs = minstrel_remove_sta_debugfs,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
int __init
|
|
|
|
rc80211_minstrel_init(void)
|
|
|
|
{
|
|
|
|
return ieee80211_rate_control_register(&mac80211_minstrel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rc80211_minstrel_exit(void)
|
|
|
|
{
|
|
|
|
ieee80211_rate_control_unregister(&mac80211_minstrel);
|
|
|
|
}
|
|
|
|
|