diff --git a/sys/dev/rtwn/if_rtwn_ridx.h b/sys/dev/rtwn/if_rtwn_ridx.h index 0a1ea35303f1..3894e7298702 100644 --- a/sys/dev/rtwn/if_rtwn_ridx.h +++ b/sys/dev/rtwn/if_rtwn_ridx.h @@ -105,15 +105,13 @@ rate2ridx(uint8_t rate) static __inline__ uint8_t rtwn_ctl_mcsrate(const struct ieee80211_rate_table *rt, uint8_t ridx) { - uint8_t cix, rate; + uint8_t rate; /* Check if we are using MCS rate. */ KASSERT(RTWN_RATE_IS_HT(ridx), ("bad mcs rate index %d", ridx)); rate = RTWN_RIDX_TO_MCS(ridx) | IEEE80211_RATE_MCS; - cix = rt->info[rt->rateCodeToIndex[rate]].ctlRateIndex; - KASSERT(cix != (uint8_t)-1, ("rate %d (%d) has no info", rate, ridx)); - return (rt->info[cix].dot11Rate); + return ieee80211_ctl_rate_ht(rt, rate); } /* VHT version of rtwn_ctl_mcsrate */ diff --git a/sys/net80211/_ieee80211.h b/sys/net80211/_ieee80211.h index 5c7e6110026d..c35a5cb08afa 100644 --- a/sys/net80211/_ieee80211.h +++ b/sys/net80211/_ieee80211.h @@ -380,6 +380,10 @@ struct ieee80211_channel { #define IEEE80211_RATE_SIZE 8 /* 802.11 standard */ #define IEEE80211_RATE_MAXSIZE 15 /* max rates we'll handle */ +/* + * Note (for adrian) - this can't be changed; the ieee80211_add_rates() + * and ieee80211_add_xrates() just memcpy()'s this verbatim. + */ struct ieee80211_rateset { uint8_t rs_nrates; uint8_t rs_rates[IEEE80211_RATE_MAXSIZE]; diff --git a/sys/net80211/ieee80211_amrr.c b/sys/net80211/ieee80211_amrr.c index d366bf71e367..2590be28d64c 100644 --- a/sys/net80211/ieee80211_amrr.c +++ b/sys/net80211/ieee80211_amrr.c @@ -66,7 +66,8 @@ static void amrr_node_init(struct ieee80211_node *); static void amrr_node_deinit(struct ieee80211_node *); static int amrr_update(struct ieee80211_amrr *, struct ieee80211_amrr_node *, struct ieee80211_node *); -static int amrr_rate(struct ieee80211_node *, void *, uint32_t); +static ieee80211_phy_rate_index_t amrr_rate(struct ieee80211_node *, void *, + uint32_t); static void amrr_tx_complete(const struct ieee80211_node *, const struct ieee80211_ratectl_tx_status *); static void amrr_tx_update_cb(void *, struct ieee80211_node *); @@ -310,13 +311,13 @@ amrr_update(struct ieee80211_amrr *amrr, struct ieee80211_amrr_node *amn, * Update our internal state if it's been long enough. * If the rate changes we also update ni_txrate to match. */ -static int +static ieee80211_phy_rate_index_t amrr_rate(struct ieee80211_node *ni, void *arg __unused, uint32_t iarg __unused) { struct ieee80211_amrr_node *amn = ni->ni_rctls; struct ieee80211_amrr *amrr; const struct ieee80211_rateset *rs = NULL; - int rix; + ieee80211_phy_rate_index_t rix; /* XXX should return -1 here, but drivers may not expect this... */ if (!amn) diff --git a/sys/net80211/ieee80211_amrr.h b/sys/net80211/ieee80211_amrr.h index 795cbf673e56..a9ab76c1c363 100644 --- a/sys/net80211/ieee80211_amrr.h +++ b/sys/net80211/ieee80211_amrr.h @@ -47,7 +47,7 @@ struct ieee80211_amrr { */ struct ieee80211_amrr_node { struct ieee80211_amrr *amn_amrr;/* backpointer */ - int amn_rix; /* current rate index */ + ieee80211_phy_rate_index_t amn_rix; /* current rate index */ int amn_ticks; /* time of last update */ /* statistics */ u_int amn_txcnt; diff --git a/sys/net80211/ieee80211_phy.c b/sys/net80211/ieee80211_phy.c index eaad7dde0653..16aa0d89a7b6 100644 --- a/sys/net80211/ieee80211_phy.c +++ b/sys/net80211/ieee80211_phy.c @@ -73,7 +73,7 @@ struct ieee80211_ds_plcp_hdr { static struct ieee80211_rate_table ieee80211_11b_table = { .rateCount = 4, /* XXX no PBCC */ - .info = { + .info2 = { /* short ctrl */ /* Preamble dot11Rate Rate */ [0] = { .phy = CCK, 1000, 0x00, B(2), 0 },/* 1 Mb */ @@ -86,7 +86,7 @@ static struct ieee80211_rate_table ieee80211_11b_table = { static struct ieee80211_rate_table ieee80211_11g_table = { .rateCount = 12, - .info = { + .info2 = { /* short ctrl */ /* Preamble dot11Rate Rate */ [0] = { .phy = CCK, 1000, 0x00, B(2), 0 }, @@ -106,7 +106,7 @@ static struct ieee80211_rate_table ieee80211_11g_table = { static struct ieee80211_rate_table ieee80211_11a_table = { .rateCount = 8, - .info = { + .info2 = { /* short ctrl */ /* Preamble dot11Rate Rate */ [0] = { .phy = OFDM, 6000, 0x00, B(12), 0 }, @@ -122,7 +122,7 @@ static struct ieee80211_rate_table ieee80211_11a_table = { static struct ieee80211_rate_table ieee80211_half_table = { .rateCount = 8, - .info = { + .info2 = { /* short ctrl */ /* Preamble dot11Rate Rate */ [0] = { .phy = HALF, 3000, 0x00, B(6), 0 }, @@ -138,7 +138,7 @@ static struct ieee80211_rate_table ieee80211_half_table = { static struct ieee80211_rate_table ieee80211_quarter_table = { .rateCount = 8, - .info = { + .info2 = { /* short ctrl */ /* Preamble dot11Rate Rate */ [0] = { .phy = QUART, 1500, 0x00, B(3), 0 }, @@ -154,7 +154,7 @@ static struct ieee80211_rate_table ieee80211_quarter_table = { static struct ieee80211_rate_table ieee80211_turbog_table = { .rateCount = 7, - .info = { + .info2 = { /* short ctrl */ /* Preamble dot11Rate Rate */ [0] = { .phy = TURBO, 12000, 0x00, B(12), 0 }, @@ -169,7 +169,7 @@ static struct ieee80211_rate_table ieee80211_turbog_table = { static struct ieee80211_rate_table ieee80211_turboa_table = { .rateCount = 8, - .info = { + .info2 = { /* short ctrl */ /* Preamble dot11Rate Rate */ [0] = { .phy = TURBO, 12000, 0x00, B(12), 0 }, @@ -185,7 +185,7 @@ static struct ieee80211_rate_table ieee80211_turboa_table = { static struct ieee80211_rate_table ieee80211_11ng_table = { .rateCount = 36, - .info = { + .info2 = { /* short ctrl */ /* Preamble dot11Rate Rate */ [0] = { .phy = CCK, 1000, 0x00, B(2), 0 }, @@ -233,7 +233,7 @@ static struct ieee80211_rate_table ieee80211_11ng_table = { static struct ieee80211_rate_table ieee80211_11na_table = { .rateCount = 32, - .info = { + .info2 = { /* short ctrl */ /* Preamble dot11Rate Rate */ [0] = { .phy = OFDM, 6000, 0x00, B(12), 0 }, @@ -303,12 +303,12 @@ ieee80211_setup_ratetable(struct ieee80211_rate_table *rt) int i; - for (i = 0; i < nitems(rt->rateCodeToIndex); i++) - rt->rateCodeToIndex[i] = (uint8_t) -1; + for (i = 0; i < nitems(rt->rateCodeToIndex2); i++) + rt->rateCodeToIndex2[i] = (uint8_t) -1; for (i = 0; i < rt->rateCount; i++) { - uint8_t code = rt->info[i].dot11Rate; - uint8_t cix = rt->info[i].ctlRateIndex; - uint8_t ctl_rate = rt->info[cix].dot11Rate; + ieee80211_phy_rate_code_t code = rt->info2[i].dot11Rate; + ieee80211_phy_rate_index_t cix = rt->info2[i].ctlRateIndex; + ieee80211_phy_rate_code_t ctl_rate = rt->info2[cix].dot11Rate; /* * Map without the basic rate bit. @@ -319,13 +319,13 @@ ieee80211_setup_ratetable(struct ieee80211_rate_table *rt) * For HT, use the MCS rate bit. */ code &= IEEE80211_RATE_VAL; - if (rt->info[i].phy == IEEE80211_T_HT) { + if (rt->info2[i].phy == IEEE80211_T_HT) { code |= IEEE80211_RATE_MCS; } /* XXX assume the control rate is non-MCS? */ ctl_rate &= IEEE80211_RATE_VAL; - rt->rateCodeToIndex[code] = i; + rt->rateCodeToIndex2[code] = i; /* * XXX for 11g the control rate to use for 5.5 and 11 Mb/s @@ -337,9 +337,9 @@ ieee80211_setup_ratetable(struct ieee80211_rate_table *rt) * current rate, so control rate's reverse lookup entry * has been installed and following call is safe. */ - rt->info[i].lpAckDuration = ieee80211_compute_duration(rt, + rt->info2[i].lpAckDuration = ieee80211_compute_duration(rt, WLAN_CTRL_FRAME_SIZE, ctl_rate, 0); - rt->info[i].spAckDuration = ieee80211_compute_duration(rt, + rt->info2[i].spAckDuration = ieee80211_compute_duration(rt, WLAN_CTRL_FRAME_SIZE, ctl_rate, IEEE80211_F_SHPREAMBLE); } @@ -502,19 +502,19 @@ uint16_t ieee80211_compute_duration(const struct ieee80211_rate_table *rt, uint32_t frameLen, uint16_t rate, int isShortPreamble) { - uint8_t rix = rt->rateCodeToIndex[rate]; + uint8_t rix = rt->rateCodeToIndex2[rate]; uint32_t bitsPerSymbol, numBits, numSymbols, phyTime, txTime; uint32_t kbps; KASSERT(rix != (uint8_t)-1, ("rate %d has no info", rate)); - kbps = rt->info[rix].rateKbps; + kbps = rt->info2[rix].rateKbps; if (kbps == 0) /* XXX bandaid for channel changes */ return 0; - switch (rt->info[rix].phy) { + switch (rt->info2[rix].phy) { case IEEE80211_T_CCK: phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS; - if (isShortPreamble && rt->info[rix].shortPreamble) + if (isShortPreamble && rt->info2[rix].shortPreamble) phyTime >>= 1; numBits = frameLen << 3; txTime = CCK_SIFS_TIME + phyTime @@ -562,7 +562,7 @@ ieee80211_compute_duration(const struct ieee80211_rate_table *rt, break; default: panic("%s: unknown phy %u (rate %u)\n", __func__, - rt->info[rix].phy, rate); + rt->info2[rix].phy, rate); } return txTime; } diff --git a/sys/net80211/ieee80211_phy.h b/sys/net80211/ieee80211_phy.h index f73abaff85d0..de2b3cb789b2 100644 --- a/sys/net80211/ieee80211_phy.h +++ b/sys/net80211/ieee80211_phy.h @@ -33,6 +33,24 @@ * IEEE 802.11 PHY-related definitions. */ +/* + * The implementation of a phy rate code. + * + * This is currently a representation of a PHY rate, including + * enough information to discern the PHY type and rate. + * It does not include whether or not it is a basic rate. + */ +typedef uint32_t ieee80211_phy_rate_code_t; + +/* + * An index into the rate table. + * + * The index is/was traditionally a uint8_t supporting up + * to 256 entries; enough for CCK, OFDM, Turbo and HT rates. + * It will need to expand to handle VHT and later rates. + */ +typedef uint8_t ieee80211_phy_rate_index_t; + /* * Contention window (slots). */ @@ -83,25 +101,25 @@ struct ieee80211_channel; struct ieee80211_rate_table { int rateCount; /* NB: for proper padding */ - uint8_t rateCodeToIndex[256]; /* back mapping */ + ieee80211_phy_rate_index_t rateCodeToIndex2[256]; /* back mapping */ struct { uint8_t phy; /* CCK/OFDM/TURBO */ uint32_t rateKbps; /* transfer rate in kbs */ uint8_t shortPreamble; /* mask for enabling short * preamble in CCK rate code */ - uint8_t dot11Rate; /* value for supported rates + ieee80211_phy_rate_code_t dot11Rate; /* value for supported rates * info element of MLME */ - uint8_t ctlRateIndex; /* index of next lower basic + ieee80211_phy_rate_index_t ctlRateIndex; /* index of next lower basic * rate; used for dur. calcs */ uint16_t lpAckDuration; /* long preamble ACK dur. */ uint16_t spAckDuration; /* short preamble ACK dur. */ - } info[IEEE80211_RATE_TABLE_SIZE]; + } info2[IEEE80211_RATE_TABLE_SIZE]; }; const struct ieee80211_rate_table *ieee80211_get_ratetable( struct ieee80211_channel *); -static __inline__ uint8_t +static __inline__ ieee80211_phy_rate_code_t ieee80211_ack_rate(const struct ieee80211_rate_table *rt, uint8_t rate) { /* @@ -111,13 +129,14 @@ ieee80211_ack_rate(const struct ieee80211_rate_table *rt, uint8_t rate) */ KASSERT(! (rate & 0x80), ("rate %d is basic/mcs?", rate)); - uint8_t cix = rt->info[rt->rateCodeToIndex[rate & IEEE80211_RATE_VAL]].ctlRateIndex; + uint8_t cix = rt->info2[rt->rateCodeToIndex2[rate & IEEE80211_RATE_VAL]].ctlRateIndex; KASSERT(cix != (uint8_t)-1, ("rate %d has no info", rate)); - return rt->info[cix].dot11Rate; + return rt->info2[cix].dot11Rate; } -static __inline__ uint8_t -ieee80211_ctl_rate(const struct ieee80211_rate_table *rt, uint8_t rate) +static __inline__ ieee80211_phy_rate_code_t +ieee80211_ctl_rate(const struct ieee80211_rate_table *rt, + ieee80211_phy_rate_code_t rate) { /* * XXX Assert this is for a legacy rate; not for an MCS rate. @@ -126,13 +145,29 @@ ieee80211_ctl_rate(const struct ieee80211_rate_table *rt, uint8_t rate) */ KASSERT(! (rate & 0x80), ("rate %d is basic/mcs?", rate)); - uint8_t cix = rt->info[rt->rateCodeToIndex[rate & IEEE80211_RATE_VAL]].ctlRateIndex; + uint8_t cix = rt->info2[rt->rateCodeToIndex2[rate & IEEE80211_RATE_VAL]].ctlRateIndex; + KASSERT(cix != (uint8_t)-1, ("rate %d has no info", rate)); + return rt->info2[cix].dot11Rate; +} + +/* + * Handle CCK/OFDM/MCS rate lookup. + * + * The caller must mask off IEEE80211_RATE_BASIC from any CCK/OFDM rates. + */ +static __inline__ ieee80211_phy_rate_code_t +ieee80211_ctl_rate_ht(const struct ieee80211_rate_table *rt, + ieee80211_phy_rate_code_t rate) +{ + + uint8_t cix = rt->info2[rt->rateCodeToIndex2[rate]].ctlRateIndex; KASSERT(cix != (uint8_t)-1, ("rate %d has no info", rate)); - return rt->info[cix].dot11Rate; + return rt->info2[cix].dot11Rate; } static __inline__ enum ieee80211_phytype -ieee80211_rate2phytype(const struct ieee80211_rate_table *rt, uint8_t rate) +ieee80211_rate2phytype(const struct ieee80211_rate_table *rt, + ieee80211_phy_rate_code_t rate) { /* * XXX Assert this is for a legacy rate; not for an MCS rate. @@ -141,13 +176,14 @@ ieee80211_rate2phytype(const struct ieee80211_rate_table *rt, uint8_t rate) */ KASSERT(! (rate & 0x80), ("rate %d is basic/mcs?", rate)); - uint8_t rix = rt->rateCodeToIndex[rate & IEEE80211_RATE_VAL]; + uint8_t rix = rt->rateCodeToIndex2[rate & IEEE80211_RATE_VAL]; KASSERT(rix != (uint8_t)-1, ("rate %d has no info", rate)); - return rt->info[rix].phy; + return rt->info2[rix].phy; } static __inline__ int -ieee80211_isratevalid(const struct ieee80211_rate_table *rt, uint8_t rate) +ieee80211_isratevalid(const struct ieee80211_rate_table *rt, + ieee80211_phy_rate_code_t rate) { /* * XXX Assert this is for a legacy rate; not for an MCS rate. @@ -156,7 +192,7 @@ ieee80211_isratevalid(const struct ieee80211_rate_table *rt, uint8_t rate) */ KASSERT(! (rate & 0x80), ("rate %d is basic/mcs?", rate)); - return rt->rateCodeToIndex[rate] != (uint8_t)-1; + return rt->rateCodeToIndex2[rate] != (uint8_t)-1; } /* @@ -167,28 +203,28 @@ ieee80211_isratevalid(const struct ieee80211_rate_table *rt, uint8_t rate) */ static __inline__ uint16_t ieee80211_ack_duration(const struct ieee80211_rate_table *rt, - uint8_t rate, int isShortPreamble) + ieee80211_phy_rate_code_t rate, int isShortPreamble) { - uint8_t rix = rt->rateCodeToIndex[rate]; + uint8_t rix = rt->rateCodeToIndex2[rate]; KASSERT(rix != (uint8_t)-1, ("rate %d has no info", rate)); if (isShortPreamble) { - KASSERT(rt->info[rix].spAckDuration != 0, + KASSERT(rt->info2[rix].spAckDuration != 0, ("shpreamble ack dur is not computed!\n")); - return rt->info[rix].spAckDuration; + return rt->info2[rix].spAckDuration; } else { - KASSERT(rt->info[rix].lpAckDuration != 0, + KASSERT(rt->info2[rix].lpAckDuration != 0, ("lgpreamble ack dur is not computed!\n")); - return rt->info[rix].lpAckDuration; + return rt->info2[rix].lpAckDuration; } } -static __inline__ uint8_t +static __inline__ ieee80211_phy_rate_index_t ieee80211_legacy_rate_lookup(const struct ieee80211_rate_table *rt, - uint8_t rate) + ieee80211_phy_rate_code_t rate) { - return (rt->rateCodeToIndex[rate & IEEE80211_RATE_VAL]); + return (rt->rateCodeToIndex2[rate & IEEE80211_RATE_VAL]); } /* diff --git a/sys/net80211/ieee80211_ratectl.h b/sys/net80211/ieee80211_ratectl.h index 2eae34763ed4..176d98a05cb5 100644 --- a/sys/net80211/ieee80211_ratectl.h +++ b/sys/net80211/ieee80211_ratectl.h @@ -89,7 +89,8 @@ struct ieee80211_ratectl { void (*ir_deinit)(struct ieee80211vap *); void (*ir_node_init)(struct ieee80211_node *); void (*ir_node_deinit)(struct ieee80211_node *); - int (*ir_rate)(struct ieee80211_node *, void *, uint32_t); + ieee80211_phy_rate_index_t (*ir_rate)(struct ieee80211_node *, void *, + uint32_t); void (*ir_tx_complete)(const struct ieee80211_node *, const struct ieee80211_ratectl_tx_status *); void (*ir_tx_update)(struct ieee80211vap *, @@ -127,7 +128,7 @@ ieee80211_ratectl_node_deinit(struct ieee80211_node *ni) vap->iv_rate->ir_node_deinit(ni); } -static int __inline +static ieee80211_phy_rate_index_t __inline ieee80211_ratectl_rate(struct ieee80211_node *ni, void *arg, uint32_t iarg) { const struct ieee80211vap *vap = ni->ni_vap; diff --git a/sys/net80211/ieee80211_ratectl_none.c b/sys/net80211/ieee80211_ratectl_none.c index 47f88cbd3a79..4c632ae98773 100644 --- a/sys/net80211/ieee80211_ratectl_none.c +++ b/sys/net80211/ieee80211_ratectl_none.c @@ -71,10 +71,10 @@ none_node_deinit(struct ieee80211_node *ni) { } -static int +static ieee80211_phy_rate_index_t none_rate(struct ieee80211_node *ni, void *arg __unused, uint32_t iarg __unused) { - int rix = 0; + ieee80211_phy_rate_index_t rix = 0; ieee80211_node_set_txrate_dot11rate(ni, ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL); diff --git a/sys/net80211/ieee80211_rssadapt.c b/sys/net80211/ieee80211_rssadapt.c index 965f53b3f2c0..658a8198358d 100644 --- a/sys/net80211/ieee80211_rssadapt.c +++ b/sys/net80211/ieee80211_rssadapt.c @@ -84,7 +84,7 @@ static void rssadapt_deinit(struct ieee80211vap *); static void rssadapt_updatestats(struct ieee80211_rssadapt_node *); static void rssadapt_node_init(struct ieee80211_node *); static void rssadapt_node_deinit(struct ieee80211_node *); -static int rssadapt_rate(struct ieee80211_node *, void *, uint32_t); +static ieee80211_phy_rate_index_t rssadapt_rate(struct ieee80211_node *, void *, uint32_t); static void rssadapt_lower_rate(struct ieee80211_rssadapt_node *, int, int); static void rssadapt_raise_rate(struct ieee80211_rssadapt_node *, int, int); @@ -234,14 +234,15 @@ bucket(int pktlen) return thridx; } -static int +static ieee80211_phy_rate_index_t rssadapt_rate(struct ieee80211_node *ni, void *arg __unused, uint32_t iarg) { struct ieee80211_rssadapt_node *ra = ni->ni_rctls; u_int pktlen = iarg; const struct ieee80211_rateset *rs; uint16_t (*thrs)[IEEE80211_RATE_SIZE]; - int rix, rssi; + int rssi; + ieee80211_phy_rate_index_t rix; /* XXX should return -1 here, but drivers may not expect this... */ if (!ra)