Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp248825rdb; Mon, 18 Sep 2023 13:59:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZgyDbOxDT1SzSB8UvriK9oS4a6+cSPBm+V6KfZ1pMl5wuuihUOkQE9IM+hWym83iTH+Ih X-Received: by 2002:a17:902:6806:b0:1c3:7628:fcb5 with SMTP id h6-20020a170902680600b001c37628fcb5mr9333204plk.62.1695070779175; Mon, 18 Sep 2023 13:59:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695070779; cv=none; d=google.com; s=arc-20160816; b=OdXmSA7vPAyAbmPGy9As55QElY217ByCoj3wyZv/wQ6NQMS90rl7ksceYR5X15KIQ/ GuSvIB0G5m5pt/yFULW7slbDKZmROrUCnD3+oHmvI6kBDzuxH1xaxIhbBkTiM8grXdt4 314knfjk/+nFNS8sHI5l4OMPjLKNFSFo1OwkZ8Z/LY9y4/dQr/AIBwEeRWXWJdEKndM1 yUsyR9wNEAdKGNGGzaFIpw5S+BpHkhtfZJn8ZuD6itj4CkUP9Znl0lZrFLwW3n/Zw262 LcpsviU4U5U7l9IRbPnb+/C/16A5uH1c0rImtXr9dIJ8RtdaFzMqpyBdMg6WpLGGCeAV ogbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i1m5iQC6GhTPIMC1Y3cHH/v4+zzZpH4Q2Jqg/D1IYYo=; fh=Y2IfAqdjkYQAx7XZcGq/8JceY1atOOwfX771vvMvH7o=; b=x5oxkGBGKScgswIOBNqgJH1eeygdBxzd/3DpcKG7sm8UqLienCXC0ry1lgfn2UUGGl 7NltqhVf3h7oAckgXnidua6xTgCQ/dKjrK1j2lFNQrUhayajx4ar4yz1/4woO2Z7fGT/ oRfp+pdzK4v4e4JeRzUG56UxSqxJ0e8BcRhq1torgilvH7RnPJXsXGcMYi2GFoHJ17Am 2G6ms4h1yIp3oAw3rUh2GfBtdQTWPeeGDFJNbPYcUUpMaqybZLQlgcm0XMM1XZSneHi/ e3z5nOUAwuVAKHsQCL/NbB9+zw+dNIh0l+ADlQNxZMWpMfGQzjH+MD5SQdNZWSPL/ZN3 kTzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HRQrLtll; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id z13-20020a1709027e8d00b001c3671d3151si3820363pla.92.2023.09.18.13.59.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 13:59:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HRQrLtll; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 9A29780E5BA3; Mon, 18 Sep 2023 04:13:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241168AbjIRLMs (ORCPT + 57 others); Mon, 18 Sep 2023 07:12:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241283AbjIRLMU (ORCPT ); Mon, 18 Sep 2023 07:12:20 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02FC9FD for ; Mon, 18 Sep 2023 04:12:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695035534; x=1726571534; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=h7L8l3DVL8SAidJyfMIyfoou06woHdwaQ+W7GI2J6+A=; b=HRQrLtllXJI+RvOB27m+/aMRB8bt/D03OlXakYoH7lUb3r5vuqOFC4SO NDSD+YupjHGag2jPkiR8LGBA8ECk441+7LJoD8GRdZBJ5+UgXLjt1SsNK jX63Gu+nNtzI8CUTV2LiROGt+jcKPHnbkldaJE/gRf6+So6pHkjrqbQ3P //EtsFZ4JnTlmyMKrLOt4Q55iZPJR4hxO2+fWnDOcDYW0z52PlVYKCLP6 lBhbe3YsOud3SSpX32fVXmsH+vBRyHON4fzmZfX1bP3zzhf9nLNqXkBzM FCLiHXcIFTxlUu50CcuYNogUMnKiRk49+SRpPkH/8WvhCBVOTFb4HLgOV g==; X-IronPort-AV: E=McAfee;i="6600,9927,10836"; a="378535955" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="378535955" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2023 04:12:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10836"; a="861025542" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="861025542" Received: from guyarad-mobl.ger.corp.intel.com (HELO ggreenma-mobl2.lan) ([10.214.215.14]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2023 04:12:12 -0700 From: gregory.greenman@intel.com To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, Johannes Berg , Gregory Greenman Subject: [PATCH 15/18] wifi: mac80211: support antenna control in injection Date: Mon, 18 Sep 2023 14:11:00 +0300 Message-Id: <20230918140607.9803b6d8dd83.I00ccb762a806ea62bc3d728fa3a0d29f4f285eeb@changeid> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230918111103.435195-1-gregory.greenman@intel.com> References: <20230918111103.435195-1-gregory.greenman@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 18 Sep 2023 04:13:22 -0700 (PDT) From: Johannes Berg 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 Signed-off-by: Gregory Greenman --- 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 6e8913dbbff6..e344708c21da 100644 --- a/include/linux/ieee80211.h +++ b/include/linux/ieee80211.h @@ -1698,6 +1698,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