git: 06b7335701fa - main - rtwn: add rtwn_ctl_vhtrate(), some cleanups

From: Adrian Chadd <adrian_at_FreeBSD.org>
Date: Tue, 31 Dec 2024 19:13:35 UTC
The branch main has been updated by adrian:

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

commit 06b7335701fac54d752445e7d2b2c15c301f90dc
Author:     Adrian Chadd <adrian@FreeBSD.org>
AuthorDate: 2024-12-15 22:58:13 +0000
Commit:     Adrian Chadd <adrian@FreeBSD.org>
CommitDate: 2024-12-31 19:13:26 +0000

    rtwn: add rtwn_ctl_vhtrate(), some cleanups
    
    * remove the hard-coded ridx values in rate2ridx(), use the RIDX
      defines for CCK/OFDM rates
    
    * Add a placeholder rtwn_ctl_vhtrate() which returns the dot11rate
      control rate to use for the given VHT rate index.  Since net80211
      currently doesn't have any VHT PHY tables, there's no mapping for
      us to leverage so just return OFDM 12M for now.
    
    * Use the new macro to convert rate index to MCS rate
    
    * Add a printf() in rate2ridx if it's passed a HT/VHT rate.
    
    Differential Revision:  https://reviews.freebsd.org/D48098
    Reviewed by:    bz
---
 sys/dev/rtwn/if_rtwn_ridx.h | 45 ++++++++++++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 15 deletions(-)

diff --git a/sys/dev/rtwn/if_rtwn_ridx.h b/sys/dev/rtwn/if_rtwn_ridx.h
index 6193f9ee2cad..0a1ea35303f1 100644
--- a/sys/dev/rtwn/if_rtwn_ridx.h
+++ b/sys/dev/rtwn/if_rtwn_ridx.h
@@ -82,20 +82,22 @@ rate2ridx(uint8_t rate)
 	}
 	switch (rate) {
 	/* 11g */
-	case 12:	return 4;
-	case 18:	return 5;
-	case 24:	return 6;
-	case 36:	return 7;
-	case 48:	return 8;
-	case 72:	return 9;
-	case 96:	return 10;
-	case 108:	return 11;
+	case 12:	return (RTWN_RIDX_OFDM6);
+	case 18:	return (RTWN_RIDX_OFDM9);
+	case 24:	return (RTWN_RIDX_OFDM12);
+	case 36:	return (RTWN_RIDX_OFDM18);
+	case 48:	return (RTWN_RIDX_OFDM24);
+	case 72:	return (RTWN_RIDX_OFDM36);
+	case 96:	return (RTWN_RIDX_OFDM48);
+	case 108:	return (RTWN_RIDX_OFDM54);
 	/* 11b */
-	case 2:		return 0;
-	case 4:		return 1;
-	case 11:	return 2;
-	case 22:	return 3;
-	default:	return RTWN_RIDX_UNKNOWN;
+	case 2:		return (RTWN_RIDX_CCK1);
+	case 4:		return (RTWN_RIDX_CCK2);
+	case 11:	return (RTWN_RIDX_CCK55);
+	case 22:	return (RTWN_RIDX_CCK11);
+	default:
+		printf("%s: called; unknown rate (%d)\n", __func__, rate);
+		return (RTWN_RIDX_UNKNOWN);
 	}
 }
 
@@ -108,10 +110,23 @@ rtwn_ctl_mcsrate(const struct ieee80211_rate_table *rt, uint8_t ridx)
 	/* Check if we are using MCS rate. */
 	KASSERT(RTWN_RATE_IS_HT(ridx), ("bad mcs rate index %d", ridx));
 
-	rate = (ridx - RTWN_RIDX_HT_MCS(0)) | IEEE80211_RATE_MCS;
+	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 (rt->info[cix].dot11Rate);
+}
+
+/* VHT version of rtwn_ctl_mcsrate */
+/* XXX TODO: also should move this to net80211 */
+static __inline__ uint8_t
+rtwn_ctl_vhtrate(const struct ieee80211_rate_table *rt, uint8_t ridx)
+{
+
+	/* Check if we are using VHT MCS rate. */
+	KASSERT(RTWN_RATE_IS_VHT(ridx), ("bad mcs rate index %d", ridx));
+
+	/* TODO: there's no VHT tables, so for now just stick to OFDM12 */
+	return (24);
 }
 
 #endif	/* IF_RTWN_RIDX_H */