📄 onoe.c
字号:
for (; srate >= 0 && RATE(srate) > 72; 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}static voidath_rate_cb(void *arg, struct ieee80211_node *ni){ ath_rate_update(netdev_priv(ni->ni_ic->ic_dev), ni, (long) arg);}/* * Reset the rate control state for each 802.11 state transition. */static voidath_rate_newstate(struct ieee80211vap *vap, enum ieee80211_state state){ struct ieee80211com *ic = vap->iv_ic; struct ath_softc *sc = netdev_priv(ic->ic_dev); 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 APs 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); }}/* * Examine and potentially adjust the transmit rate. */static voidath_rate_ctl(void *arg, struct ieee80211_node *ni){ struct ath_softc *sc = arg; struct onoe_node *on = ATH_NODE_ONOE(ATH_NODE(ni)); struct ieee80211_rateset *rs = &ni->ni_rates; int dir = 0, nrate, enough; sc->sc_stats.ast_rate_calls++; /* * Rate control * XXX: very primitive version. */ enough = (on->on_tx_ok + on->on_tx_err >= 10); /* no packet reached -> down */ if (on->on_tx_err > 0 && on->on_tx_ok == 0) dir = -1; /* all packets needs retry in average -> down */ if (enough && on->on_tx_ok < on->on_tx_retr) dir = -1; /* no error and less than rate_raise% of packets need retry -> up */ if (enough && on->on_tx_err == 0 && on->on_tx_retr < (on->on_tx_ok * ath_rate_raise) / 100) dir = 1; DPRINTF(sc, MAC_FMT ": ok %d err %d retr %d upper %d dir %d\n", MAC_ADDR(ni->ni_macaddr), on->on_tx_ok, on->on_tx_err, on->on_tx_retr, on->on_tx_upper, dir); nrate = ni->ni_txrate; switch (dir) { case 0: if (enough && on->on_tx_upper > 0) on->on_tx_upper--; break; case -1: if (nrate > 0) { nrate--; sc->sc_stats.ast_rate_drop++; } on->on_tx_upper = 0; break; case 1: /* raise rate if we hit rate_raise_threshold */ if (++on->on_tx_upper < ath_rate_raise_threshold) break; on->on_tx_upper = 0; if (nrate + 1 < rs->rs_nrates) { nrate++; sc->sc_stats.ast_rate_raise++; } break; } if (nrate != ni->ni_txrate) { DPRINTF(sc, "%s: %dM -> %dM (%d ok, %d err, %d retr)\n", __func__, (rs->rs_rates[ni->ni_txrate] & IEEE80211_RATE_VAL) / 2, (rs->rs_rates[nrate] & IEEE80211_RATE_VAL) / 2, on->on_tx_ok, on->on_tx_err, on->on_tx_retr); ath_rate_update(sc, ni, nrate); } else if (enough) on->on_tx_ok = on->on_tx_err = on->on_tx_retr = 0;}static struct ath_ratectrl *ath_rate_attach(struct ath_softc *sc){ struct onoe_softc *osc; _MOD_INC_USE(THIS_MODULE, return NULL); osc = kmalloc(sizeof(struct onoe_softc), GFP_ATOMIC); if (osc == NULL) { _MOD_DEC_USE(THIS_MODULE); return NULL; } osc->arc.arc_space = sizeof(struct onoe_node); osc->arc.arc_vap_space = 0; return &osc->arc;}static voidath_rate_detach(struct ath_ratectrl *arc){ struct onoe_softc *osc = (struct onoe_softc *)arc; kfree(osc); _MOD_DEC_USE(THIS_MODULE);}static int minrateinterval = 500; /* 500ms */static int maxpercent = 100; /* 100% */static int minpercent = 0; /* 0% */static int maxint = 0x7fffffff; /* 32-bit big *//* * Static (i.e. global) sysctls. */static ctl_table ath_rate_static_sysctls[] = { { .ctl_name = CTL_AUTO, .procname = "interval", .mode = 0644, .data = &ath_rateinterval, .maxlen = sizeof(ath_rateinterval), .extra1 = &minrateinterval, .extra2 = &maxint, .proc_handler = proc_dointvec_minmax }, { .ctl_name = CTL_AUTO, .procname = "raise", .mode = 0644, .data = &ath_rate_raise, .maxlen = sizeof(ath_rate_raise), .extra1 = &minpercent, .extra2 = &maxpercent, .proc_handler = proc_dointvec_minmax }, { .ctl_name = CTL_AUTO, .procname = "raise_threshold", .mode = 0644, .data = &ath_rate_raise_threshold, .maxlen = sizeof(ath_rate_raise_threshold), .proc_handler = proc_dointvec }, { 0 }};static ctl_table ath_rate_table[] = { { .ctl_name = CTL_AUTO, .procname = "rate_onoe", .mode = 0555, .child = ath_rate_static_sysctls }, { 0 }};static ctl_table ath_ath_table[] = { { .ctl_name = DEV_ATH, .procname = "ath", .mode = 0555, .child = ath_rate_table }, { 0 }};static ctl_table ath_root_table[] = { { .ctl_name = CTL_DEV, .procname = "dev", .mode = 0555, .child = ath_ath_table }, { 0 }};static struct ctl_table_header *ath_sysctl_header;static struct ieee80211_rate_ops ath_rate_ops = { .ratectl_id = IEEE80211_RATE_ONOE, .node_init = ath_rate_node_init, .node_cleanup = ath_rate_node_cleanup, .findrate = ath_rate_findrate, .get_mrr = ath_rate_get_mrr, .tx_complete = ath_rate_tx_complete, .newassoc = ath_rate_newassoc, .newstate = ath_rate_newstate, .attach = ath_rate_attach, .detach = ath_rate_detach,};#include "release.h"#if 0static char *version = "1.0 (" RELEASE_VERSION ")";static char *dev_info = "ath_rate_onoe";#endifMODULE_AUTHOR("Errno Consulting, Sam Leffler");MODULE_DESCRIPTION("Atsushi Onoe's rate control algorithm for Atheros devices");#ifdef MODULE_VERSIONMODULE_VERSION(RELEASE_VERSION);#endif#ifdef MODULE_LICENSEMODULE_LICENSE("Dual BSD/GPL");#endifstatic int __initinit_ath_rate_onoe(void){ int ret = ieee80211_rate_register(&ath_rate_ops); if (ret) return ret; ath_sysctl_header = ATH_REGISTER_SYSCTL_TABLE(ath_root_table); return (0);}module_init(init_ath_rate_onoe);static void __exitexit_ath_rate_onoe(void){ if (ath_sysctl_header != NULL) unregister_sysctl_table(ath_sysctl_header); ieee80211_rate_unregister(&ath_rate_ops);}module_exit(exit_ath_rate_onoe);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -