git: 3d69926189f5 - main - rtwn: expand the ridx numbers to include VHT; add accessor macros
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 07 Dec 2024 07:14:54 UTC
The branch main has been updated by adrian: URL: https://cgit.FreeBSD.org/src/commit/?id=3d69926189f5ee72b3c762d27661a45d883909a2 commit 3d69926189f5ee72b3c762d27661a45d883909a2 Author: Adrian Chadd <adrian@FreeBSD.org> AuthorDate: 2024-12-04 04:45:48 +0000 Commit: Adrian Chadd <adrian@FreeBSD.org> CommitDate: 2024-12-07 07:13:50 +0000 rtwn: expand the ridx numbers to include VHT; add accessor macros * expand the ridx field all the way through 4x4 11n (MCS0..MCS31) * and then expand it through VHT 4x4 (MCS0..9 for each stream) * add accessor macros to check if the rate is HT, VHT * use accessor macros to check if the rate is HT rather than comparing it against OFDM54 or RIDX_HT_MCS(0); the values aobve HT MCS will be VHT, and we don't want to trigger on those! * add a couple of appropriate TODO VHT bits in the TX path Locally tested: * RTL8192CU, STA mode * RTL8188EU, STA mode * RTL8821AU, STA mode * RTL8192EU, STA mode Differential Revision: https://reviews.freebsd.org/D47896 --- sys/dev/rtwn/if_rtwn_ridx.h | 35 ++++++++++++++++++++++++++++++----- sys/dev/rtwn/rtl8188e/r88e_chan.c | 2 +- sys/dev/rtwn/rtl8188e/r88e_rx.c | 5 ++--- sys/dev/rtwn/rtl8192c/r92c_chan.c | 4 ++-- sys/dev/rtwn/rtl8192c/r92c_fw.c | 4 ++-- sys/dev/rtwn/rtl8192c/r92c_rx.c | 8 ++++---- sys/dev/rtwn/rtl8192c/r92c_tx.c | 4 ++-- sys/dev/rtwn/rtl8192e/r92e_chan.c | 2 +- sys/dev/rtwn/rtl8812a/r12a_rx.c | 13 ++++++------- sys/dev/rtwn/rtl8812a/r12a_tx.c | 6 ++++-- 10 files changed, 54 insertions(+), 29 deletions(-) diff --git a/sys/dev/rtwn/if_rtwn_ridx.h b/sys/dev/rtwn/if_rtwn_ridx.h index dd93f2db4ccf..6193f9ee2cad 100644 --- 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 @@ rtwn_ctl_mcsrate(const struct ieee80211_rate_table *rt, uint8_t ridx) 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 index c072b3554083..51474bc1b819 100644 --- a/sys/dev/rtwn/rtl8188e/r88e_chan.c +++ b/sys/dev/rtwn/rtl8188e/r88e_chan.c @@ -99,7 +99,7 @@ r88e_get_txpower(struct rtwn_softc *sc, int chain, /* 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 index 826076c8071c..287869885b86 100644 --- a/sys/dev/rtwn/rtl8188e/r88e_rx.c +++ b/sys/dev/rtwn/rtl8188e/r88e_rx.c @@ -120,9 +120,8 @@ r88e_ratectl_tx_complete(struct rtwn_softc *sc, uint8_t *buf, int len) 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 index 0edb32a97b4d..55d73c934f1e 100644 --- a/sys/dev/rtwn/rtl8192c/r92c_chan.c +++ b/sys/dev/rtwn/rtl8192c/r92c_chan.c @@ -97,13 +97,13 @@ r92c_get_txpower(struct rtwn_softc *sc, int chain, /* 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 index 5ab56a5f454e..e611e5addeb3 100644 --- a/sys/dev/rtwn/rtl8192c/r92c_fw.c +++ b/sys/dev/rtwn/rtl8192c/r92c_fw.c @@ -195,9 +195,9 @@ r92c_send_ra_cmd(struct rtwn_softc *sc, int macid, uint32_t rates, #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 index 72f726a24550..9af3b1ebc2c9 100644 --- a/sys/dev/rtwn/rtl8192c/r92c_rx.c +++ b/sys/dev/rtwn/rtl8192c/r92c_rx.c @@ -121,7 +121,7 @@ r92c_get_rx_stats(struct rtwn_softc *sc, struct ieee80211_rx_stats *rxs, 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 @@ r92c_get_rx_stats(struct rtwn_softc *sc, struct ieee80211_rx_stats *rxs, 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 @@ r92c_get_rx_stats(struct rtwn_softc *sc, struct ieee80211_rx_stats *rxs, 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 index 8a4c6581832b..9583a7e1119e 100644 --- a/sys/dev/rtwn/rtl8192c/r92c_tx.c +++ b/sys/dev/rtwn/rtl8192c/r92c_tx.c @@ -95,7 +95,7 @@ r92c_tx_protection(struct rtwn_softc *sc, struct r92c_tx_desc *txd, 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 @@ r92c_fill_tx_desc(struct rtwn_softc *sc, struct ieee80211_node *ni, 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 index b28462873c09..c6e911309cd2 100644 --- a/sys/dev/rtwn/rtl8192e/r92e_chan.c +++ b/sys/dev/rtwn/rtl8192e/r92e_chan.c @@ -137,7 +137,7 @@ r92e_get_txpower(struct rtwn_softc *sc, int chain, struct ieee80211_channel *c, 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 index 763397636ac9..482e4ee38c81 100644 --- a/sys/dev/rtwn/rtl8812a/r12a_rx.c +++ b/sys/dev/rtwn/rtl8812a/r12a_rx.c @@ -107,9 +107,8 @@ r12a_ratectl_tx_complete(struct rtwn_softc *sc, uint8_t *buf, int len) 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 @@ r12a_get_rx_stats(struct rtwn_softc *sc, struct ieee80211_rx_stats *rxs, 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 @@ r12a_get_rx_stats(struct rtwn_softc *sc, struct ieee80211_rx_stats *rxs, /* 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 @@ r12a_get_rx_stats(struct rtwn_softc *sc, struct ieee80211_rx_stats *rxs, } /* 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 @@ r12a_get_rx_stats(struct rtwn_softc *sc, struct ieee80211_rx_stats *rxs, } 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 index 8b16be17f8eb..822416a09618 100644 --- a/sys/dev/rtwn/rtl8812a/r12a_tx.c +++ b/sys/dev/rtwn/rtl8812a/r12a_tx.c @@ -103,7 +103,8 @@ r12a_tx_protection(struct rtwn_softc *sc, struct r12a_tx_desc *txd, 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 @@ r12a_fill_tx_desc(struct rtwn_softc *sc, struct ieee80211_node *ni, 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);