Linux wireless drivers development
 help / color / mirror / Atom feed
From: Kieran Frewen <kieran.frewen@morsemicro.com>
To: johannes@sipsolutions.net
Cc: linux-wireless@vger.kernel.org, quic_jjohnson@quicinc.com,
	Kieran Frewen <kieran.frewen@morsemicro.com>
Subject: [PATCH v2 11/12] cfg80211: support for calculating S1G bitrates
Date: Tue, 30 Aug 2022 02:20:16 +0000	[thread overview]
Message-ID: <20220830022017.51017-12-kieran.frewen@morsemicro.com> (raw)
In-Reply-To: <20220830022017.51017-1-kieran.frewen@morsemicro.com>

Support for reporting and calculating S1G MCS bitrates.

Signed-off-by: Kieran Frewen <kieran.frewen@morsemicro.com>
---
 net/wireless/util.c | 113 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 113 insertions(+)

diff --git a/net/wireless/util.c b/net/wireless/util.c
index aeccb6ce595c..d9d7dde3d4f2 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -1384,6 +1384,117 @@ static u32 cfg80211_calculate_bitrate_vht(struct rate_info *rate)
 	return 0;
 }
 
+static u32 cfg80211_calculate_bitrate_s1g(struct rate_info *rate)
+{
+	/* For 1, 2, 4, 8 and 16 MHz channels */
+	static const u32 base[5][12] = {
+		{  300000,
+		   600000,
+		   900000,
+		  1200000,
+		  1800000,
+		  2400000,
+		  2700000,
+		  3000000,
+		  3600000,
+		  4000000,
+		  /* MCS 10 supported in 1 MHz only */
+		  150000,
+		},
+		{  650000,
+		  1300000,
+		  1950000,
+		  2600000,
+		  3900000,
+		  5200000,
+		  5850000,
+		  6500000,
+		  7800000,
+		  /* MCS 9 not valid */
+		},
+		{  1350000,
+		   2700000,
+		   4050000,
+		   5400000,
+		   8100000,
+		  10800000,
+		  12150000,
+		  13500000,
+		  16200000,
+		  18000000,
+		},
+		{  2925000,
+		   5850000,
+		   8775000,
+		  11700000,
+		  17550000,
+		  23400000,
+		  26325000,
+		  29250000,
+		  35100000,
+		  39000000,
+		},
+		{  8580000,
+		  11700000,
+		  17550000,
+		  23400000,
+		  35100000,
+		  46800000,
+		  52650000,
+		  58500000,
+		  70200000,
+		  78000000,
+		},
+	};
+	u32 bitrate;
+	/* default is 1 MHz index */
+	int idx = 0;
+
+	if (rate->mcs > 11)
+		goto warn;
+
+	switch (rate->bw) {
+	case RATE_INFO_BW_16:
+		idx = 4;
+		break;
+	case RATE_INFO_BW_8:
+		idx = 3;
+		break;
+	case RATE_INFO_BW_4:
+		idx = 2;
+		break;
+	case RATE_INFO_BW_2:
+		idx = 1;
+		break;
+	case RATE_INFO_BW_1:
+		idx = 0;
+		break;
+	case RATE_INFO_BW_5:
+	case RATE_INFO_BW_10:
+	case RATE_INFO_BW_20:
+	case RATE_INFO_BW_40:
+	case RATE_INFO_BW_80:
+	case RATE_INFO_BW_160:
+	default:
+		goto warn;
+	}
+
+	bitrate = base[idx][rate->mcs];
+	bitrate *= rate->nss;
+
+	if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
+		bitrate = (bitrate / 9) * 10;
+	/* do NOT round down here */
+	return (bitrate + 50000) / 100000;
+warn:
+	if (!rate->bw && !rate->mcs && !rate->nss)
+		pr_debug("%s: rx status was not received yet!", __func__);
+	else
+		WARN_ONCE(1, "invalid rate bw=%d, mcs=%d, nss=%d\n",
+			  rate->bw, rate->mcs, rate->nss);
+	return 0;
+}
+
 static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate)
 {
 #define SCALE 6144
@@ -1612,6 +1723,8 @@ u32 cfg80211_calculate_bitrate(struct rate_info *rate)
 		return cfg80211_calculate_bitrate_he(rate);
 	if (rate->flags & RATE_INFO_FLAGS_EHT_MCS)
 		return cfg80211_calculate_bitrate_eht(rate);
+	if (rate->flags & RATE_INFO_FLAGS_S1G_MCS)
+		return cfg80211_calculate_bitrate_s1g(rate);
 
 	return rate->legacy;
 }
-- 
2.25.1


  parent reply	other threads:[~2022-08-30  2:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-30  2:20 [PATCH v2 00/12] Additional Support for 802.11ah (S1G) Kieran Frewen
2022-08-30  2:20 ` [PATCH v2 01/12] cfg80211: regulatory: extend regulatory support for S1G Kieran Frewen
2022-08-30  4:52   ` kernel test robot
2022-08-30  9:31   ` kernel test robot
2022-09-02  8:44   ` Dan Carpenter
2022-08-30  2:20 ` [PATCH v2 02/12] mac80211: update TIM for S1G specification changes Kieran Frewen
2022-08-30  2:20 ` [PATCH v2 03/12] mac80211: S1G beacon/short beacon support Kieran Frewen
2022-08-30  2:20 ` [PATCH v2 04/12] nl80211: support setting S1G short beacon period Kieran Frewen
2022-08-30  2:20 ` [PATCH v2 05/12] nl80211: support advertising S1G capabilities Kieran Frewen
2022-08-30  2:20 ` [PATCH v2 06/12] mac80211: support ieee80211_ext format Kieran Frewen
2022-08-30  2:20 ` [PATCH v2 07/12] mac80211: S1G capabilities information element in probe request Kieran Frewen
2022-08-30  2:20 ` [PATCH v2 08/12] cfg80211: S1G rate flags Kieran Frewen
2022-08-30  2:20 ` [PATCH v2 09/12] nl80211: support advertising S1G rate information Kieran Frewen
2022-08-30  2:20 ` [PATCH v2 10/12] mac80211: support S1G rate encoding Kieran Frewen
2022-08-30  2:20 ` Kieran Frewen [this message]
2022-08-30  2:20 ` [PATCH v2 12/12] mac80211_hwsim: support for S1G rate information Kieran Frewen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220830022017.51017-12-kieran.frewen@morsemicro.com \
    --to=kieran.frewen@morsemicro.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    --cc=quic_jjohnson@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox