git: 527687a9e30a - main - LinuxKPI: 80211: implement (*get_antenna) and set ic_[rt]xstream

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Sat, 03 Sep 2022 23:16:55 UTC
The branch main has been updated by bz:

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

commit 527687a9e30aef2e5e0c0c5b5e64e6059f1a37a4
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-09-03 23:11:05 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-09-03 23:11:05 +0000

    LinuxKPI: 80211: implement (*get_antenna) and set ic_[rt]xstream
    
    Implement the mac80211 (*get_antenna) call and after checking any
    antenna information present query the current configuration on startup
    (both informations should be identical at this point in theory).
    Both the wiphy variables and function call report a bitmask not a count.
    Count the bits for net80211 for as long as we get away with just a
    number in ic_[rt]xstream.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      4 days
---
 sys/compat/linuxkpi/common/src/linux_80211.c        | 17 +++++++++++++++++
 sys/compat/linuxkpi/common/src/linux_80211.h        |  1 +
 sys/compat/linuxkpi/common/src/linux_80211_macops.c | 18 ++++++++++++++++++
 3 files changed, 36 insertions(+)

diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c
index 6408f57c20c3..b4d9997897f8 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211.c
@@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/sysctl.h>
 #include <sys/queue.h>
 #include <sys/taskqueue.h>
+#include <sys/libkern.h>
 
 #include <net/if.h>
 #include <net/if_var.h>
@@ -3495,6 +3496,22 @@ linuxkpi_ieee80211_ifattach(struct ieee80211_hw *hw)
 	ic->ic_htcaps |= IEEE80211_HTCAP_TXSTBC;
 #endif
 
+	/*
+	 * The wiphy variables report bitmasks of avail antennas.
+	 * (*get_antenna) get the current bitmask sets which can be
+	 * altered by (*set_antenna) for some drivers.
+	 * XXX-BZ will the count alone do us much good long-term in net80211?
+	 */
+	if (hw->wiphy->available_antennas_rx ||
+	    hw->wiphy->available_antennas_tx) {
+		uint32_t rxs, txs;
+
+		if (lkpi_80211_mo_get_antenna(hw, &txs, &rxs) == 0) {
+			ic->ic_rxstream = bitcount32(rxs);
+			ic->ic_txstream = bitcount32(txs);
+		}
+	}
+
 	ic->ic_cryptocaps = 0;
 #ifdef LKPI_80211_HW_CRYPTO
 	if (hw->wiphy->n_cipher_suites > 0) {
diff --git a/sys/compat/linuxkpi/common/src/linux_80211.h b/sys/compat/linuxkpi/common/src/linux_80211.h
index 3c107f76de32..c6958cf834e3 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.h
+++ b/sys/compat/linuxkpi/common/src/linux_80211.h
@@ -197,6 +197,7 @@ struct lkpi_wiphy {
 
 int lkpi_80211_mo_start(struct ieee80211_hw *);
 void lkpi_80211_mo_stop(struct ieee80211_hw *);
+int lkpi_80211_mo_get_antenna(struct ieee80211_hw *, u32 *, u32 *);
 int lkpi_80211_mo_set_frag_threshold(struct ieee80211_hw *, uint32_t);
 int lkpi_80211_mo_set_rts_threshold(struct ieee80211_hw *, uint32_t);
 int lkpi_80211_mo_add_interface(struct ieee80211_hw *, struct ieee80211_vif *);
diff --git a/sys/compat/linuxkpi/common/src/linux_80211_macops.c b/sys/compat/linuxkpi/common/src/linux_80211_macops.c
index b3e01780e1ce..12cffc11481e 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211_macops.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211_macops.c
@@ -77,6 +77,24 @@ lkpi_80211_mo_stop(struct ieee80211_hw *hw)
 	lhw->sc_flags &= ~LKPI_MAC80211_DRV_STARTED;
 }
 
+int
+lkpi_80211_mo_get_antenna(struct ieee80211_hw *hw, u32 *txs, u32 *rxs)
+{
+	struct lkpi_hw *lhw;
+	int error;
+
+	lhw = HW_TO_LHW(hw);
+	if (lhw->ops->get_antenna == NULL) {
+		error = EOPNOTSUPP;
+		goto out;
+	}
+
+	error = lhw->ops->get_antenna(hw, txs, rxs);
+
+out:
+	return (error);
+}
+
 int
 lkpi_80211_mo_set_frag_threshold(struct ieee80211_hw *hw, uint32_t frag_th)
 {