git: ec07af2a3d49 - main - rtwn: announce VHT support for RTL8812AU/RTL8821AU.

From: Adrian Chadd <adrian_at_FreeBSD.org>
Date: Thu, 09 Jan 2025 00:59:13 UTC
The branch main has been updated by adrian:

URL: https://cgit.FreeBSD.org/src/commit/?id=ec07af2a3d494de36a20a541efdd24874c841db5

commit ec07af2a3d494de36a20a541efdd24874c841db5
Author:     Adrian Chadd <adrian@FreeBSD.org>
AuthorDate: 2024-12-16 04:15:46 +0000
Commit:     Adrian Chadd <adrian@FreeBSD.org>
CommitDate: 2025-01-09 00:52:12 +0000

    rtwn: announce VHT support for RTL8812AU/RTL8821AU.
    
    Although the transmit path doesn't yet support VHT rates (because
    the rate control and rate representation in net80211 doesn't yet
    know about VHT rates) the NIC will receive VHT frames but only
    transmit HT frames.
    
    Locally tested:
    
    * RTL8812AU, STA mode
    
    Differential Revision:  https://reviews.freebsd.org/D48103
---
 sys/dev/rtwn/if_rtwn.c                   | 23 +++++++++++++++++++++++
 sys/dev/rtwn/if_rtwnvar.h                |  2 ++
 sys/dev/rtwn/rtl8812a/usb/r12au_attach.c | 19 ++++++++++++++++---
 sys/dev/rtwn/rtl8821a/usb/r21au_attach.c | 17 ++++++++++++++---
 4 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/sys/dev/rtwn/if_rtwn.c b/sys/dev/rtwn/if_rtwn.c
index ed84950b1a94..f9950c5acf4d 100644
--- a/sys/dev/rtwn/if_rtwn.c
+++ b/sys/dev/rtwn/if_rtwn.c
@@ -436,6 +436,29 @@ rtwn_resume(struct rtwn_softc *sc)
 	ieee80211_resume_all(ic);
 }
 
+void
+rtwn_attach_vht_cap_info_mcs(struct rtwn_softc *sc)
+{
+	struct ieee80211com *ic = &sc->sc_ic;
+	uint32_t rx_mcs = 0, tx_mcs = 0;
+
+	for (int i = 0 ; i < 8; i++) {
+		if (i < sc->ntxchains)
+			tx_mcs |= (IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2));
+		else
+			tx_mcs |= (IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2));
+
+		if (i < sc->nrxchains)
+			rx_mcs |= (IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2));
+		else
+			rx_mcs |= (IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2));
+	}
+	ic->ic_vht_cap.supp_mcs.rx_mcs_map = rx_mcs;
+	ic->ic_vht_cap.supp_mcs.rx_highest = 0;
+	ic->ic_vht_cap.supp_mcs.tx_mcs_map = tx_mcs;
+	ic->ic_vht_cap.supp_mcs.tx_highest = 0;
+}
+
 static void
 rtwn_vap_decrement_counters(struct rtwn_softc *sc,
     enum ieee80211_opmode opmode, int id)
diff --git a/sys/dev/rtwn/if_rtwnvar.h b/sys/dev/rtwn/if_rtwnvar.h
index fa4b6d0a5df7..aa42715b1674 100644
--- a/sys/dev/rtwn/if_rtwnvar.h
+++ b/sys/dev/rtwn/if_rtwnvar.h
@@ -436,6 +436,8 @@ void	rtwn_detach(struct rtwn_softc *);
 void	rtwn_resume(struct rtwn_softc *);
 void	rtwn_suspend(struct rtwn_softc *);
 
+void	rtwn_attach_vht_cap_info_mcs(struct rtwn_softc *);
+
 /* Interface-specific. */
 #define rtwn_write_1(_sc, _addr, _val) \
 	(((_sc)->sc_write_1)((_sc), (_addr), (_val)))
diff --git a/sys/dev/rtwn/rtl8812a/usb/r12au_attach.c b/sys/dev/rtwn/rtl8812a/usb/r12au_attach.c
index c87bffb4db19..b6850eb9fa23 100644
--- a/sys/dev/rtwn/rtl8812a/usb/r12au_attach.c
+++ b/sys/dev/rtwn/rtl8812a/usb/r12au_attach.c
@@ -175,11 +175,24 @@ r12au_adj_devcaps(struct rtwn_softc *sc)
 	}
 
 	ic->ic_htcaps |=
-	    IEEE80211_HTCAP_CHWIDTH40 /* 40 MHz channel width */
-	    | IEEE80211_HTCAP_SHORTGI40 /* short GI in 40MHz */
+	    IEEE80211_HTCAP_CHWIDTH40 | /* 40 MHz channel width */
+	    IEEE80211_HTCAP_SHORTGI40 /* short GI in 40MHz */
 	;
 
-	/* TODO: STBC, VHT etc */
+	/* TODO: STBC */
+
+	/* VHT config */
+	ic->ic_flags_ext |= IEEE80211_FEXT_VHT;
+	ic->ic_vht_cap.vht_cap_info =
+	    IEEE80211_VHTCAP_MAX_MPDU_LENGTH_11454 |
+	    IEEE80211_VHTCAP_SHORT_GI_80 |
+	    IEEE80211_VHTCAP_TXSTBC |
+	    IEEE80211_VHTCAP_RXSTBC_1 |
+	    IEEE80211_VHTCAP_HTC_VHT |
+	    _IEEE80211_SHIFTMASK(7,
+	      IEEE80211_VHTCAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK);
+
+	rtwn_attach_vht_cap_info_mcs(sc);
 }
 
 void
diff --git a/sys/dev/rtwn/rtl8821a/usb/r21au_attach.c b/sys/dev/rtwn/rtl8821a/usb/r21au_attach.c
index 175bac8f6fc9..60cb6d3fc61d 100644
--- a/sys/dev/rtwn/rtl8821a/usb/r21au_attach.c
+++ b/sys/dev/rtwn/rtl8821a/usb/r21au_attach.c
@@ -160,11 +160,22 @@ r21au_adj_devcaps(struct rtwn_softc *sc)
 		ic->ic_caps |= IEEE80211_C_DFS;
 
 	ic->ic_htcaps |=
-	    IEEE80211_HTCAP_CHWIDTH40 /* 40 MHz channel width */
-	    | IEEE80211_HTCAP_SHORTGI40 /* short GI in 40MHz */
+	    IEEE80211_HTCAP_CHWIDTH40 | /* 40 MHz channel width */
+	    IEEE80211_HTCAP_SHORTGI40 /* short GI in 40MHz */
 	    ;
 
-	/* TODO: VHT */
+	/* VHT config */
+	ic->ic_flags_ext |= IEEE80211_FEXT_VHT;
+	ic->ic_vht_cap.vht_cap_info =
+	    IEEE80211_VHTCAP_MAX_MPDU_LENGTH_11454 |
+	    IEEE80211_VHTCAP_SHORT_GI_80 |
+	    IEEE80211_VHTCAP_TXSTBC |
+	    IEEE80211_VHTCAP_RXSTBC_1 |
+	    IEEE80211_VHTCAP_HTC_VHT |
+	    _IEEE80211_SHIFTMASK(7,
+	        IEEE80211_VHTCAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK);
+
+	rtwn_attach_vht_cap_info_mcs(sc);
 }
 
 void