Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Feb 2025 19:31:49 GMT
From:      Adrian Chadd <adrian@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: ff0e22f88d04 - main - net80211: add ieee80211_phy_vht_get_mcs_kbit()
Message-ID:  <202502261931.51QJVnfr018885@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by adrian:

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

commit ff0e22f88d041da2a146d70140a535c57b40c16d
Author:     Adrian Chadd <adrian@FreeBSD.org>
AuthorDate: 2025-01-15 05:09:27 +0000
Commit:     Adrian Chadd <adrian@FreeBSD.org>
CommitDate: 2025-02-26 19:31:25 +0000

    net80211: add ieee80211_phy_vht_get_mcs_kbit()
    
    Add ieee80211_phy_vht_get_mcs_kbit(), which calculates the VHT rate
    in kbit/sec.
    
    Differential Revision:  https://reviews.freebsd.org/D48612
---
 sys/net80211/ieee80211_phy.c | 85 ++++++++++++++++++++++++++++++++++++++++++++
 sys/net80211/ieee80211_phy.h |  2 ++
 2 files changed, 87 insertions(+)

diff --git a/sys/net80211/ieee80211_phy.c b/sys/net80211/ieee80211_phy.c
index 9c2b1197564a..eb96d74a2bd9 100644
--- a/sys/net80211/ieee80211_phy.c
+++ b/sys/net80211/ieee80211_phy.c
@@ -707,3 +707,88 @@ ieee80211_phy_vht_validate_mcs(enum ieee80211_sta_rx_bw bw, uint8_t nss,
 
 	return ((mask & (1 << mcs)) != 0);
 }
+
+struct mcs_entry {
+	int n_sym;	/* Number of bits per symbol */
+	int cod_n;	/* Coding rate numerator */
+	int cod_d;	/* Coding rate denominator */
+};
+
+/*
+ * These parameters are taken from 802.11-2020 Table 21-29
+ * (VHT-MCSs for Mandatory 20 MHZ, Nss=1).
+ *
+ * n_sym corresponds to "Nbpscs", cod_n/cod_d corresponds to
+ * "R".
+ */
+static struct mcs_entry mcs_entries[] = {
+	{ 1, 1, 2 },    /* MCS0 */
+	{ 2, 1, 2 },
+	{ 2, 3, 4 },
+	{ 4, 1, 2 },
+	{ 4, 3, 4 },
+	{ 6, 2, 3 },
+	{ 6, 3, 4 },
+	{ 6, 5, 6 },
+	{ 8, 3, 4 },
+	{ 8, 5, 6 },    /* MCS9 */
+};
+
+/**
+ * @brief Calculate the bitrate of the given VHT MCS rate.
+ *
+ * @param bw		Channel bandwidth (enum ieee80211_sta_rx_bw)
+ * @param nss		Number of spatial streams, 1..8
+ * @param mcs		MCS, 0..9
+ * @param is_shortgi	True if short guard-interval (400nS)
+ *			false otherwise (800nS)
+ *
+ * @returns		The bitrate in kbit/sec.
+ */
+uint32_t
+ieee80211_phy_vht_get_mcs_kbit(enum ieee80211_sta_rx_bw bw,
+    uint8_t nss, uint8_t mcs, bool is_shortgi)
+{
+	uint32_t sym_len, n_carriers;
+
+	/* Validate MCS 0..9, NSS 1..8 */
+	if (mcs > 9)
+		return (0);
+	if (nss == 0 || nss > 8)
+		return (0);
+
+	/*
+	 * Short-GI - 3.6uS symbol time, long-GI - 4.0uS symbol time
+	 *
+	 * See 802.11-2020 Table 21-5 (Timing-related constraints.)
+	 */
+	if (is_shortgi)
+		sym_len = 36;
+	else
+		sym_len = 40;
+
+	/*
+	 * Calculate the number of carriers for the given channel bandwidth
+	 *
+	 * See 802.11-2020 Table 21-5 (Timing-related constraints.)
+	 */
+	switch (bw) {
+	case IEEE80211_STA_RX_BW_20:
+		n_carriers = 52;
+		break;
+	case IEEE80211_STA_RX_BW_40:
+		n_carriers = 108;
+		break;
+	case IEEE80211_STA_RX_BW_80:
+		n_carriers = 234;
+		break;
+	case IEEE80211_STA_RX_BW_160:
+		n_carriers = 468;
+		break;
+	default:
+		return (0);
+	}
+
+	return ((n_carriers * mcs_entries[mcs].n_sym * mcs_entries[mcs].cod_n *
+	    nss * 10000) / (mcs_entries[mcs].cod_d * sym_len));
+}
diff --git a/sys/net80211/ieee80211_phy.h b/sys/net80211/ieee80211_phy.h
index 466f59584f2c..749b082e34e9 100644
--- a/sys/net80211/ieee80211_phy.h
+++ b/sys/net80211/ieee80211_phy.h
@@ -227,6 +227,8 @@ uint16_t	ieee80211_phy_vht_get_mcs_mask(enum ieee80211_sta_rx_bw,
 		    uint8_t);
 bool		ieee80211_phy_vht_validate_mcs(enum ieee80211_sta_rx_bw,
 		    uint8_t, uint8_t);
+uint32_t	ieee80211_phy_vht_get_mcs_kbit(enum ieee80211_sta_rx_bw,
+		    uint8_t, uint8_t, bool);
 
 #endif	/* _KERNEL */
 #endif	/* !_NET80211_IEEE80211_PHY_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202502261931.51QJVnfr018885>