diff --git a/sys/dev/rtwn/if_rtwn_ridx.h b/sys/dev/rtwn/if_rtwn_ridx.h --- a/sys/dev/rtwn/if_rtwn_ridx.h +++ b/sys/dev/rtwn/if_rtwn_ridx.h @@ -22,6 +22,11 @@ #define IF_RTWN_RIDX_H /* HW rate indices. */ + +/* + * Note - these are also used as offsets into the TX power table + * array. + */ #define RTWN_RIDX_CCK1 0 #define RTWN_RIDX_CCK2 1 #define RTWN_RIDX_CCK55 2 @@ -37,13 +42,34 @@ #define RTWN_RIDX_HT_MCS_SHIFT 12 #define RTWN_RIDX_HT_MCS(i) (RTWN_RIDX_HT_MCS_SHIFT + (i)) +#define RTWN_RIDX_TO_MCS(ridx) ((ridx) - RTWN_RIDX_HT_MCS_SHIFT) + +/* HT supports up to MCS31, so goes from 12 -> 43 */ + +#define RTWN_RIDX_LEGACY_HT_COUNT 44 + +/* + * VHT supports MCS0..9 for up to 4 spatial streams, so + * goes from 44 -> 83. + */ +#define RTWN_RIDX_VHT_MCS_SHIFT 44 +#define RTWN_RIDX_VHT_MCS(s, i) (RTWN_RIDX_VHT_MCS_SHIFT + ((10*s) + i)) + +/* + * The total amount of rate indexes, CCK, OFDM, HT MCS0..31, + * VHT MCS0..9 for 1-4 streams. + */ +#define RTWN_RIDX_COUNT 84 -#define RTWN_RIDX_COUNT 28 #define RTWN_RIDX_UNKNOWN (uint8_t)-1 -#define RTWN_RATE_IS_CCK(rate) ((rate) <= RTWN_RIDX_CCK11) +#define RTWN_RATE_IS_CCK(rate) ((rate) <= RTWN_RIDX_CCK11) #define RTWN_RATE_IS_OFDM(rate) \ - ((rate) >= RTWN_RIDX_OFDM6 && (rate) != RTWN_RIDX_UNKNOWN) + ((rate) >= RTWN_RIDX_OFDM6 && (rate) <= RTWN_RIDX_OFDM54) +#define RTWN_RATE_IS_HT(rate) \ + ((rate) >= RTWN_RIDX_HT_MCS_SHIFT && (rate) < RTWN_RIDX_VHT_MCS_SHIFT) +#define RTWN_RATE_IS_VHT(rate) \ + ((rate) >= RTWN_RIDX_VHT_MCS_SHIFT && (rate) <= RTWN_RIDX_COUNT) static const uint8_t ridx2rate[] = { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 }; @@ -80,8 +106,7 @@ uint8_t cix, rate; /* Check if we are using MCS rate. */ - KASSERT(ridx >= RTWN_RIDX_HT_MCS(0) && ridx != RTWN_RIDX_UNKNOWN, - ("bad mcs rate index %d", ridx)); + KASSERT(RTWN_RATE_IS_HT(ridx), ("bad mcs rate index %d", ridx)); rate = (ridx - RTWN_RIDX_HT_MCS(0)) | IEEE80211_RATE_MCS; cix = rt->info[rt->rateCodeToIndex[rate]].ctlRateIndex; diff --git a/sys/dev/rtwn/rtl8188e/r88e_chan.c b/sys/dev/rtwn/rtl8188e/r88e_chan.c --- a/sys/dev/rtwn/rtl8188e/r88e_chan.c +++ b/sys/dev/rtwn/rtl8188e/r88e_chan.c @@ -99,7 +99,7 @@ /* XXX net80211 regulatory */ max_mcs = RTWN_RIDX_HT_MCS(sc->ntxchains * 8 - 1); - KASSERT(max_mcs <= RTWN_RIDX_COUNT, ("increase ridx limit\n")); + KASSERT(max_mcs <= RTWN_RIDX_LEGACY_HT_COUNT, ("increase ridx limit\n")); /* Compute per-CCK rate Tx power. */ cckpow = rt->cck_tx_pwr[group]; diff --git a/sys/dev/rtwn/rtl8188e/r88e_rx.c b/sys/dev/rtwn/rtl8188e/r88e_rx.c --- a/sys/dev/rtwn/rtl8188e/r88e_rx.c +++ b/sys/dev/rtwn/rtl8188e/r88e_rx.c @@ -120,9 +120,8 @@ txs.flags = IEEE80211_RATECTL_STATUS_LONG_RETRY | IEEE80211_RATECTL_STATUS_FINAL_RATE; txs.long_retries = ntries; - if (rpt->final_rate > RTWN_RIDX_OFDM54) { /* MCS */ - txs.final_rate = - rpt->final_rate - RTWN_RIDX_HT_MCS_SHIFT; + if (RTWN_RATE_IS_HT(rpt->final_rate)) { /* MCS */ + txs.final_rate = RTWN_RIDX_TO_MCS(rpt->final_rate); txs.final_rate |= IEEE80211_RATE_MCS; } else txs.final_rate = ridx2rate[rpt->final_rate]; diff --git a/sys/dev/rtwn/rtl8192c/r92c_chan.c b/sys/dev/rtwn/rtl8192c/r92c_chan.c --- a/sys/dev/rtwn/rtl8192c/r92c_chan.c +++ b/sys/dev/rtwn/rtl8192c/r92c_chan.c @@ -97,13 +97,13 @@ /* XXX net80211 regulatory */ max_mcs = RTWN_RIDX_HT_MCS(sc->ntxchains * 8 - 1); - KASSERT(max_mcs <= RTWN_RIDX_COUNT, ("increase ridx limit\n")); + KASSERT(max_mcs <= RTWN_RIDX_LEGACY_HT_COUNT, ("increase ridx limit\n")); if (rs->regulatory == 0) { for (ridx = RTWN_RIDX_CCK1; ridx <= RTWN_RIDX_CCK11; ridx++) power[ridx] = base[chain].pwr[0][ridx]; } - for (ridx = RTWN_RIDX_OFDM6; ridx < RTWN_RIDX_COUNT; ridx++) { + for (ridx = RTWN_RIDX_OFDM6; ridx < RTWN_RIDX_LEGACY_HT_COUNT; ridx++) { if (rs->regulatory == 3) { power[ridx] = base[chain].pwr[0][ridx]; /* Apply vendor limits. */ diff --git a/sys/dev/rtwn/rtl8192c/r92c_fw.c b/sys/dev/rtwn/rtl8192c/r92c_fw.c --- a/sys/dev/rtwn/rtl8192c/r92c_fw.c +++ b/sys/dev/rtwn/rtl8192c/r92c_fw.c @@ -195,9 +195,9 @@ #endif /* Set rates mask for unicast frames. */ - if (maxrate >= RTWN_RIDX_HT_MCS(0)) + if (RTWN_RATE_IS_HT(maxrate)) mode = R92C_RAID_11GN; - else if (maxrate >= RTWN_RIDX_OFDM6) + else if (RTWN_RATE_IS_OFDM(maxrate)) mode = R92C_RAID_11BG; else mode = R92C_RAID_11B; diff --git a/sys/dev/rtwn/rtl8192c/r92c_rx.c b/sys/dev/rtwn/rtl8192c/r92c_rx.c --- a/sys/dev/rtwn/rtl8192c/r92c_rx.c +++ b/sys/dev/rtwn/rtl8192c/r92c_rx.c @@ -121,7 +121,7 @@ rxs->c_pktflags |= IEEE80211_RX_F_AMPDU; else if (rxdw1 & R92C_RXDW1_AMPDU_MORE) rxs->c_pktflags |= IEEE80211_RX_F_AMPDU_MORE; - if ((rxdw3 & R92C_RXDW3_SPLCP) && rate >= RTWN_RIDX_HT_MCS(0)) + if ((rxdw3 & R92C_RXDW3_SPLCP) && RTWN_RATE_IS_HT(rate)) rxs->c_pktflags |= IEEE80211_RX_F_SHORTGI; if (rxdw3 & R92C_RXDW3_HT40) @@ -131,13 +131,13 @@ if (RTWN_RATE_IS_CCK(rate)) rxs->c_phytype = IEEE80211_RX_FP_11B; - else if (rate < RTWN_RIDX_HT_MCS(0)) + else if (RTWN_RATE_IS_OFDM(rate)) rxs->c_phytype = IEEE80211_RX_FP_11G; else rxs->c_phytype = IEEE80211_RX_FP_11NG; /* Map HW rate index to 802.11 rate. */ - if (rate < RTWN_RIDX_HT_MCS(0)) { + if (RTWN_RATE_IS_CCK(rate) || RTWN_RATE_IS_OFDM(rate)) { rxs->c_rate = ridx2rate[rate]; if (RTWN_RATE_IS_CCK(rate)) rxs->c_pktflags |= IEEE80211_RX_F_CCK; @@ -145,7 +145,7 @@ rxs->c_pktflags |= IEEE80211_RX_F_OFDM; } else { /* MCS0~15. */ rxs->c_rate = - IEEE80211_RATE_MCS | (rate - RTWN_RIDX_HT_MCS_SHIFT); + IEEE80211_RATE_MCS | (RTWN_RIDX_TO_MCS(rate)); rxs->c_pktflags |= IEEE80211_RX_F_HT; } } diff --git a/sys/dev/rtwn/rtl8192c/r92c_tx.c b/sys/dev/rtwn/rtl8192c/r92c_tx.c --- a/sys/dev/rtwn/rtl8192c/r92c_tx.c +++ b/sys/dev/rtwn/rtl8192c/r92c_tx.c @@ -95,7 +95,7 @@ if (mode == IEEE80211_PROT_CTSONLY || mode == IEEE80211_PROT_RTSCTS) { - if (ridx >= RTWN_RIDX_HT_MCS(0)) + if (RTWN_RATE_IS_HT(ridx)) rate = rtwn_ctl_mcsrate(ic->ic_rt, ridx); else rate = ieee80211_ctl_rate(ic->ic_rt, ridx2rate[ridx]); @@ -314,7 +314,7 @@ txd->txdw4 |= htole32(R92C_TXDW4_DATA_SHPRE); prot = IEEE80211_PROT_NONE; - if (ridx >= RTWN_RIDX_HT_MCS(0)) { + if (RTWN_RATE_IS_HT(ridx)) { r92c_tx_set_ht40(sc, txd, ni); r92c_tx_set_sgi(sc, txd, ni); prot = ic->ic_htprotmode; diff --git a/sys/dev/rtwn/rtl8192e/r92e_chan.c b/sys/dev/rtwn/rtl8192e/r92e_chan.c --- a/sys/dev/rtwn/rtl8192e/r92e_chan.c +++ b/sys/dev/rtwn/rtl8192e/r92e_chan.c @@ -137,7 +137,7 @@ if (sc->sc_debug & RTWN_DEBUG_TXPWR) { /* Dump per-rate Tx power values. */ printf("Tx power for chain %d:\n", chain); - for (ridx = RTWN_RIDX_CCK1; ridx < RTWN_RIDX_COUNT; ridx++) + for (ridx = RTWN_RIDX_CCK1; ridx < RTWN_RIDX_LEGACY_HT_COUNT; ridx++) printf("Rate %d = %u\n", ridx, power[ridx]); } #endif diff --git a/sys/dev/rtwn/rtl8812a/r12a_rx.c b/sys/dev/rtwn/rtl8812a/r12a_rx.c --- a/sys/dev/rtwn/rtl8812a/r12a_rx.c +++ b/sys/dev/rtwn/rtl8812a/r12a_rx.c @@ -107,9 +107,8 @@ txs.flags = IEEE80211_RATECTL_STATUS_LONG_RETRY | IEEE80211_RATECTL_STATUS_FINAL_RATE; txs.long_retries = ntries; - if (rpt->final_rate > RTWN_RIDX_OFDM54) { /* MCS */ - txs.final_rate = - rpt->final_rate - RTWN_RIDX_HT_MCS_SHIFT; + if (RTWN_RATE_IS_HT(rpt->final_rate)) { /* MCS */ + txs.final_rate = RTWN_RIDX_TO_MCS(rpt->final_rate); txs.final_rate |= IEEE80211_RATE_MCS; } else txs.final_rate = ridx2rate[rpt->final_rate]; @@ -247,7 +246,7 @@ rxs->c_pktflags |= IEEE80211_RX_F_AMPDU_MORE; } - if ((rxdw4 & R12A_RXDW4_SPLCP) && rate >= RTWN_RIDX_HT_MCS(0)) + if ((rxdw4 & R12A_RXDW4_SPLCP) && RTWN_RATE_IS_HT(rate)) rxs->c_pktflags |= IEEE80211_RX_F_SHORTGI; switch (MS(rxdw4, R12A_RXDW4_BW)) { @@ -273,7 +272,7 @@ /* XXX check with RTL8812AU */ is5ghz = (physt->cfosho[2] != 0x01); - if (rate < RTWN_RIDX_HT_MCS(0)) { + if (RTWN_RATE_IS_CCK(rate) || RTWN_RATE_IS_OFDM(rate)) { if (is5ghz) rxs->c_phytype = IEEE80211_RX_FP_11A; else @@ -287,7 +286,7 @@ } /* Map HW rate index to 802.11 rate. */ - if (rate < RTWN_RIDX_HT_MCS(0)) { + if (RTWN_RATE_IS_CCK(rate) || RTWN_RATE_IS_OFDM(rate)) { rxs->c_rate = ridx2rate[rate]; if (RTWN_RATE_IS_CCK(rate)) rxs->c_pktflags |= IEEE80211_RX_F_CCK; @@ -296,7 +295,7 @@ } else { /* MCS0~15. */ /* TODO: VHT rates */ rxs->c_rate = - IEEE80211_RATE_MCS | (rate - RTWN_RIDX_HT_MCS_SHIFT); + IEEE80211_RATE_MCS | RTWN_RIDX_TO_MCS(rate); rxs->c_pktflags |= IEEE80211_RX_F_HT; } diff --git a/sys/dev/rtwn/rtl8812a/r12a_tx.c b/sys/dev/rtwn/rtl8812a/r12a_tx.c --- a/sys/dev/rtwn/rtl8812a/r12a_tx.c +++ b/sys/dev/rtwn/rtl8812a/r12a_tx.c @@ -103,7 +103,8 @@ if (mode == IEEE80211_PROT_CTSONLY || mode == IEEE80211_PROT_RTSCTS) { - if (ridx >= RTWN_RIDX_HT_MCS(0)) + /* TODO: VHT */ + if (RTWN_RATE_IS_HT(ridx)) rate = rtwn_ctl_mcsrate(ic->ic_rt, ridx); else rate = ieee80211_ctl_rate(ic->ic_rt, ridx2rate[ridx]); @@ -325,7 +326,8 @@ txd->txdw5 |= htole32(R12A_TXDW5_DATA_SHORT); prot = IEEE80211_PROT_NONE; - if (ridx >= RTWN_RIDX_HT_MCS(0)) { + /* TODO: VHT */ + if (RTWN_RATE_IS_HT(ridx)) { r12a_tx_set_ht40(sc, txd, ni); r12a_tx_set_sgi(sc, txd, ni); r12a_tx_set_ldpc(sc, txd, ni);