All of lore.kernel.org
 help / color / mirror / Atom feed
From: gregory.greenman@intel.com
To: johannes@sipsolutions.net
Cc: linux-wireless@vger.kernel.org,
	Johannes Berg <johannes.berg@intel.com>,
	Gregory Greenman <gregory.greenman@intel.com>
Subject: [PATCH v2 15/18] wifi: mac80211: support antenna control in injection
Date: Wed, 20 Sep 2023 21:25:26 +0300	[thread overview]
Message-ID: <20230920211508.f71001aa4da9.I00ccb762a806ea62bc3d728fa3a0d29f4f285eeb@changeid> (raw)
In-Reply-To: <20230920182529.659973-1-gregory.greenman@intel.com>

From: Johannes Berg <johannes.berg@intel.com>

Support antenna control for injection by parsing the antenna
radiotap field (which may be presented multiple times) and
telling the driver about the resulting antenna bitmap. Of
course there's no guarantee the driver will actually honour
this, just like any other injection control.

If misconfigured, i.e. the injected HT/VHT MCS needs more
chains than antennas are configured, the bitmap is reset to
zero, indicating no selection.

For now this is only set up for two anntenas so we keep more
free bits, but that can be trivially extended if any driver
implements support for it that can deal with hardware with
more antennas.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Gregory Greenman <gregory.greenman@intel.com>
---
 include/linux/ieee80211.h |  2 ++
 include/net/mac80211.h    |  6 +++++-
 net/mac80211/tx.c         | 14 ++++++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
index f2965ff3d7c1..3b02f038d509 100644
--- a/include/linux/ieee80211.h
+++ b/include/linux/ieee80211.h
@@ -1705,6 +1705,8 @@ struct ieee80211_mcs_info {
 #define		IEEE80211_HT_MCS_TX_MAX_STREAMS	4
 #define IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION	0x10
 
+#define IEEE80211_HT_MCS_CHAINS(mcs) ((mcs) == 32 ? 1 : (1 + ((mcs) >> 3)))
+
 /*
  * 802.11n D5.0 20.3.5 / 20.6 says:
  * - indices 0 to 7 and 32 are single spatial stream
diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index b3df8cb2919b..b67583ddae9c 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -1178,7 +1178,11 @@ struct ieee80211_tx_info {
 					u8 use_cts_prot:1;
 					u8 short_preamble:1;
 					u8 skip_table:1;
-					/* 2 bytes free */
+
+					/* for injection only (bitmap) */
+					u8 antennas:2;
+
+					/* 14 bits free */
 				};
 				/* only needed before rate control */
 				unsigned long jiffies;
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 932516f8cc13..a984fc54644e 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -2162,6 +2162,11 @@ bool ieee80211_parse_tx_radiotap(struct sk_buff *skb,
 			rate_found = true;
 			break;
 
+		case IEEE80211_RADIOTAP_ANTENNA:
+			/* this can appear multiple times, keep a bitmap */
+			info->control.antennas |= BIT(*iterator.this_arg);
+			break;
+
 		case IEEE80211_RADIOTAP_DATA_RETRIES:
 			rate_retries = *iterator.this_arg;
 			break;
@@ -2256,8 +2261,17 @@ bool ieee80211_parse_tx_radiotap(struct sk_buff *skb,
 		}
 
 		if (rate_flags & IEEE80211_TX_RC_MCS) {
+			/* reset antennas if not enough */
+			if (IEEE80211_HT_MCS_CHAINS(rate) >
+					hweight8(info->control.antennas))
+				info->control.antennas = 0;
+
 			info->control.rates[0].idx = rate;
 		} else if (rate_flags & IEEE80211_TX_RC_VHT_MCS) {
+			/* reset antennas if not enough */
+			if (vht_nss > hweight8(info->control.antennas))
+				info->control.antennas = 0;
+
 			ieee80211_rate_set_vht(info->control.rates, vht_mcs,
 					       vht_nss);
 		} else if (sband) {
-- 
2.38.1


  parent reply	other threads:[~2023-09-20 18:27 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-20 18:25 [PATCH v2 00/18] cfg80211/mac80211 patches from our internal tree 2023-09-18 gregory.greenman
2023-09-20 18:25 ` [PATCH v2 01/18] wifi: mac80211: use bandwidth indication element for CSA gregory.greenman
2023-09-20 18:25 ` [PATCH v2 02/18] wifi: mac80211: update the rx_chains after set_antenna() gregory.greenman
2023-09-20 18:25 ` [PATCH v2 03/18] wifi: mac80211: don't connect to an AP while it's in a CSA process gregory.greenman
2023-09-20 18:25 ` [PATCH v2 04/18] wifi: mac80211: relax RCU check in for_each_vif_active_link() gregory.greenman
2023-09-20 18:25 ` [PATCH v2 05/18] wifi: mac80211: allow for_each_sta_active_link() under RCU gregory.greenman
2023-09-20 18:25 ` [PATCH v2 06/18] wifi: cfg80211: reg: describe return values in kernel-doc gregory.greenman
2023-09-20 18:25 ` [PATCH v2 07/18] wifi: mac80211: " gregory.greenman
2023-09-20 18:25 ` [PATCH v2 08/18] wifi: mac80211_hwsim: move kernel-doc description gregory.greenman
2023-09-20 18:25 ` [PATCH v2 09/18] wifi: cfg80211: Fix 6GHz scan configuration gregory.greenman
2023-09-20 18:25 ` [PATCH v2 10/18] wifi: mac80211: work around Cisco AP 9115 VHT MPDU length gregory.greenman
2023-09-20 18:25 ` [PATCH v2 11/18] wifi: mac80211: Notify the low level driver on change in MLO valid links gregory.greenman
2023-09-20 18:25 ` [PATCH v2 12/18] wifi: mac80211_hwsim: Handle BSS_CHANGED_VALID_LINKS gregory.greenman
2023-09-20 18:25 ` [PATCH v2 13/18] wifi: mac80211: add support for parsing TID to Link mapping element gregory.greenman
2023-09-20 18:25 ` [PATCH v2 14/18] wifi: mac80211: support handling of advertised TID-to-link mapping gregory.greenman
2023-09-20 18:25 ` gregory.greenman [this message]
2023-09-20 18:25 ` [PATCH v2 16/18] wifi: cfg80211: report per-link errors during association gregory.greenman
2023-09-20 18:25 ` [PATCH v2 17/18] wifi: mac80211: report per-link error " gregory.greenman
2023-09-20 18:25 ` [PATCH v2 18/18] wifi: mac80211: reject MLO channel configuration if not supported gregory.greenman

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=20230920211508.f71001aa4da9.I00ccb762a806ea62bc3d728fa3a0d29f4f285eeb@changeid \
    --to=gregory.greenman@intel.com \
    --cc=johannes.berg@intel.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.