git: cc3b7b7e715d - main - ath_hal_ar9300: implement the TX/RX chainmask override for AR9300 HAL

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

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

commit cc3b7b7e715dde516752c479bc67eb93467d86a6
Author:     Adrian Chadd <adrian@FreeBSD.org>
AuthorDate: 2024-12-29 05:25:42 +0000
Commit:     Adrian Chadd <adrian@FreeBSD.org>
CommitDate: 2024-12-31 01:35:56 +0000

    ath_hal_ar9300: implement the TX/RX chainmask override for AR9300 HAL
    
    This commit implements the missing capability set handlers for
    setting the transmit and receive chainmasks.  I did this for the
    AR5416 and later chips years ago, but not for these.
    
    This is especially useful when you're only hooking up one or two
    antennas on a 3 antenna device - or you just want to test it like
    that.
    
    It also requires updating the number of supported transmit/receive
    streams, so also add them here.
    
    Locally Tested:
    
    * AR9300, STA mode, 1, 2 and 3 stream TX/RX configuration
    
    Differential Revision:  https://reviews.freebsd.org/D48240
---
 sys/contrib/dev/ath/ath_hal/ar9300/ar9300_attach.c |  2 +-
 sys/contrib/dev/ath/ath_hal/ar9300/ar9300_misc.c   | 29 +++++++++++++++++++++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/sys/contrib/dev/ath/ath_hal/ar9300/ar9300_attach.c b/sys/contrib/dev/ath/ath_hal/ar9300/ar9300_attach.c
index ca41cae2c5eb..26ef2c67b882 100644
--- a/sys/contrib/dev/ath/ath_hal/ar9300/ar9300_attach.c
+++ b/sys/contrib/dev/ath/ath_hal/ar9300/ar9300_attach.c
@@ -2751,7 +2751,7 @@ ar9300_fill_capability_info(struct ath_hal *ah)
     /* FreeBSD: Update number of TX/RX streams */
     p_cap->halTxStreams = owl_get_ntxchains(p_cap->halTxChainMask);
     p_cap->halRxStreams = owl_get_ntxchains(p_cap->halRxChainMask);
-
+#undef owl_get_ntxchains
 
     /*
      * This being a newer chip supports TKIP non-splitmic mode.
diff --git a/sys/contrib/dev/ath/ath_hal/ar9300/ar9300_misc.c b/sys/contrib/dev/ath/ath_hal/ar9300/ar9300_misc.c
index 1793cf06378b..94bcc1777f27 100644
--- a/sys/contrib/dev/ath/ath_hal/ar9300/ar9300_misc.c
+++ b/sys/contrib/dev/ath/ath_hal/ar9300/ar9300_misc.c
@@ -968,7 +968,7 @@ ar9300_set_capability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,
         u_int32_t capability, u_int32_t setting, HAL_STATUS *status)
 {
     struct ath_hal_9300 *ahp = AH9300(ah);
-    const HAL_CAPABILITIES *p_cap = &AH_PRIVATE(ah)->ah_caps;
+    HAL_CAPABILITIES *p_cap = &AH_PRIVATE(ah)->ah_caps;
     u_int32_t v;
 
     switch (type) {
@@ -1079,6 +1079,33 @@ ar9300_set_capability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,
             return AH_TRUE;
         }
         return AH_FALSE;
+
+#define owl_get_ntxchains(_txchainmask) \
+        (((_txchainmask >> 2) & 1) + ((_txchainmask >> 1) & 1) + \
+        (_txchainmask & 1))
+
+    case HAL_CAP_RX_CHAINMASK:
+        setting &= ar9300_eeprom_get(ahp, EEP_RX_MASK);
+        p_cap->halRxChainMask = setting;
+        p_cap->halRxStreams = owl_get_ntxchains(setting);
+        if (p_cap->halRxStreams > 3)
+            p_cap->halRxStreams = 3;
+        else if (p_cap->halRxStreams < 1)
+            p_cap->halRxStreams = 1;
+        return AH_TRUE;
+
+    case HAL_CAP_TX_CHAINMASK:
+        setting &= ar9300_eeprom_get(ahp, EEP_TX_MASK);
+        p_cap->halTxChainMask = setting;
+        p_cap->halTxStreams = owl_get_ntxchains(setting);
+        if (p_cap->halTxStreams > 3)
+            p_cap->halTxStreams = 3;
+        else if (p_cap->halTxStreams < 1)
+            p_cap->halTxStreams = 1;
+        return AH_TRUE;
+
+#undef owl_get_ntxchains
+
         /* fall thru... */
     default:
         return ath_hal_setcapability(ah, type, capability, setting, status);