/*- * Copyright (c) 2010 , MWNL * 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. * */
/*--------------------------------------------------------------------*/ /* * Default parameters for the rate control algorithm. These are * all tunable with sysctls. The rate controller runs periodically * (each ath_rateinterval ms) analyzing transmit statistics for each * neighbor/station (when operating in station mode this is only the AP). * If transmits look to be working well over a sampling period then * it gives a "raise rate credit". If transmits look to not be working * well than it deducts a credit. If the credits cross a threshold then * the transmit rate is raised. Various error conditions force the * the transmit rate to be dropped. * * The decision to issue/deduct a credit is based on the errors and * retries accumulated over the sampling period. ath_rate_raise defines * the percent of retransmits for which a credit is issued/deducted. * ath_rate_raise_threshold defines the threshold on credits at which * the transmit rate is increased. * * XXX this algorithm is flawed.
/*---------------------------------------------------------------------* * FUNCTION: ath_rate_node_init(struct ath_softc *sc, struct ath_node *an) * DESCRIPTION: initialize the node *---------------------------------------------------------------------*/ void ath_rate_node_init(struct ath_softc *sc, struct ath_node *an) { /* NB: assumed to be zero'd by caller */ ath_rate_update(sc, &an->an_node, 0); } EXPORT_SYMBOL(ath_rate_node_init);
/*---------------------------------------------------------------------* * FUNCTION: ath_rate_node_cleanup(struct ath_softc *sc, struct ath_node *an) * DESCRIPTION: destroy information for a node *---------------------------------------------------------------------*/ void ath_rate_node_cleanup(struct ath_softc *sc, struct ath_node *an) { } EXPORT_SYMBOL(ath_rate_node_cleanup);
/*---------------------------------------------------------------------* * FUNCTION: ath_rate_findrate(struct ath_softc *sc, struct ath_node *an, int shortPreamble, size_t frameLen, u_int8_t *rix, int *try0, u_int8_t *txrate) * DESCRIPTION: find bit rate for the current packet tx *---------------------------------------------------------------------*/
/*---------------------------------------------------------------------* * FUNCTION: ath_rate_tx_complete(struct ath_softc *sc, struct ath_node *an, const struct ath_desc *ds) * DESCRIPTION: post Tx handling (per packet basis) Increment the bit rate if the tx_ok = 10(successive) Decrement the bit rate if tx_err = 2 (successive) *---------------------------------------------------------------------*/
* DESCRIPTION: handle the new association *---------------------------------------------------------------------*/ void ath_rate_newassoc(struct ath_softc *sc, struct ath_node *an, int isnew) { if (isnew) ath_rate_ctl_start(sc, &an->an_node); } EXPORT_SYMBOL(ath_rate_newassoc);
DPRINTF(sc, "%s: set xmit rate for %s to %dM\n", __func__, ether_sprintf(ni->ni_macaddr), ni->ni_rates.rs_nrates > 0 ? (ni->ni_rates.rs_rates[rate] & IEEE80211_RATE_VAL) / 2 : 0);
ni->ni_txrate = rate; /* * Before associating a node has no rate set setup * so we can't calculate any transmit codes to use. * This is ok since we should never be sending anything * but management frames and those always go at the * lowest hardware rate. */ if (ni->ni_rates.rs_nrates == 0) goto done; on->on_tx_rix0 = sc->sc_rixmap[ni->ni_rates.rs_rates[rate] & IEEE80211_RATE_VAL]; on->on_tx_rate0 = rt->info[on->on_tx_rix0].rateCode;
on->on_tx_rate0sp = on->on_tx_rate0 | rt->info[on->on_tx_rix0].shortPreamble; if (sc->sc_mrretry) { /* * Hardware supports multi-rate retry; setup two * step-down retry rates and make the lowest rate * be the ``last chance''. We use 4, 2, 2, 2 tries * respectively (4 is set here, the rest are fixed * in the xmit routine). */ on->on_tx_try0 = 1; /*right now 1 as no retr handled, 4 tries at rate 0 */ if (--rate >= 0) { rix = sc->sc_rixmap[ni->ni_rates.rs_rates[rate]&IEEE80211_RATE_VAL]; on->on_tx_rate1 = rt->info[rix].rateCode; on->on_tx_rate1sp = on->on_tx_rate1 | rt->info[rix].shortPreamble; } else on->on_tx_rate1 = on->on_tx_rate1sp = 0; if (--rate >= 0) { rix = sc->sc_rixmap[ni->ni_rates.rs_rates[rate]&IEEE80211_RATE_VAL]; on->on_tx_rate2 = rt->info[rix].rateCode; on->on_tx_rate2sp = on->on_tx_rate2 | rt->info[rix].shortPreamble; } else on->on_tx_rate2 = on->on_tx_rate2sp = 0; if (rate > 0) { /* NB: only do this if we didn't already do it above */ on->on_tx_rate3 = rt->info[0].rateCode; on->on_tx_rate3sp = on->on_tx_rate3 | rt->info[0].shortPreamble; } else on->on_tx_rate3 = on->on_tx_rate3sp = 0; } else { on->on_tx_try0 = 1; //ATH_TXMAXTRY; /* max tries at rate 0 */ on->on_tx_rate1 = on->on_tx_rate1sp = 0; on->on_tx_rate2 = on->on_tx_rate2sp = 0; on->on_tx_rate3 = on->on_tx_rate3sp = 0; } done: on->on_tx_ok = on->on_tx_err = on->on_tx_retr = on->on_tx_upper = 0; }
* DESCRIPTION: Set the starting transmit rate for a node. *---------------------------------------------------------------------*/ static void ath_rate_ctl_start(struct ath_softc *sc, struct ieee80211_node *ni) { #define RATE(_ix) (ni->ni_rates.rs_rates[(_ix)] & IEEE80211_RATE_VAL) struct ieee80211vap *vap = ni->ni_vap; int srate;
KASSERT(ni->ni_rates.rs_nrates > 0, ("no rates")); if (vap->iv_fixed_rate == IEEE80211_FIXED_RATE_NONE) { /* * No fixed rate is requested. For 11b start with * the highest negotiated rate; otherwise, for 11g * and 11a, we start "in the middle" at 24Mb or 36Mb. */ srate = ni->ni_rates.rs_nrates - 1; if (sc->sc_curmode != IEEE80211_MODE_11B) { /* * Scan the negotiated rate set to find the * closest rate. */ /* NB: the rate set is assumed sorted */
/*PROBABLY CHANGE 72 TO 108 FOR STARTING WITH 54M */ for (; srate >= 0 && RATE(srate) > 108; srate--); KASSERT(srate >= 0, ("bogus rate set")); } } else { /* * A fixed rate is to be used; iv_fixed_rate is the * 802.11 rate code. Convert this to the index into * the negotiated rate set for the node. We know the * rate is there because the rate set is checked when * the station associates. */ /* NB: the rate set is assumed sorted */ srate = ni->ni_rates.rs_nrates - 1; for (; srate >= 0 && RATE(srate) != vap->iv_fixed_rate; srate--); KASSERT(srate >= 0, ("fixed rate %d not in rate set", vap->iv_fixed_rate)); } ath_rate_update(sc, ni, srate); #undef RATE }
* DESCRIPTION: Reset the rate control state for each 802.11 state transition. *---------------------------------------------------------------------*/ void ath_rate_newstate(struct ieee80211vap *vap, enum ieee80211_state state) { struct ieee80211com *ic = vap->iv_ic; struct ath_softc *sc = ic->ic_dev->priv; struct ieee80211_node *ni;
if (state == IEEE80211_S_INIT) return; if (vap->iv_opmode == IEEE80211_M_STA) { /* * Reset local xmit state; this is really only * meaningful when operating in station mode. */ ni = vap->iv_bss; if (state == IEEE80211_S_RUN) { ath_rate_ctl_start(sc, ni); } else { ath_rate_update(sc, ni, 0); } } else { /* * When operating as a station the node table holds * the AP's that were discovered during scanning. * For any other operating mode we want to reset the * tx rate state of each node. */ ieee80211_iterate_nodes(&ic->ic_sta, ath_rate_cb, NULL); ath_rate_update(sc, vap->iv_bss, 0); } } EXPORT_SYMBOL(ath_rate_newstate); /*---------------------------------------------------------------------* * FUNCTION: ath_rate_ctl(void *arg, struct ieee80211_node *ni)
* DESCRIPTION: Examine and potentially adjust the transmit rate. *---------------------------------------------------------------------*/ static void ath_rate_ctl(void *arg, struct ieee80211_node *ni) { struct ath_softc *sc = arg; struct arf_node *on = ATH_NODE_ARF(ATH_NODE(ni)); struct ieee80211_rateset *rs = &ni->ni_rates; int dir = 0, nrate;
sc->sc_stats.ast_rate_calls++;
if(on->on_tx_ok == 10) dir = 1; /*increase bit rate*/ if(on->on_tx_err == 2) dir = -1; /*decrease bit rate*/
nrate = ni->ni_txrate; /*Current bit rate*/
switch(dir) { case 0: { /*maintain the same bit rate*/ break; } case -1: { /*decrement the bit rate by one index*/ if (nrate > 0) { nrate--; sc->sc_stats.ast_rate_drop++; } break; } case 1: { /*Increment the bit rate by one index*/ if (nrate + 1 < rs->rs_nrates) { nrate++; sc->sc_stats.ast_rate_raise++; } break; } default: break; }
DPRINTF(sc, "%s: ok %d err %d retr %d upper %d dir %d\n", ether_sprintf(ni->ni_macaddr), on->on_tx_ok, on->on_tx_err, on->on_tx_retr, on->on_tx_upper, dir);