git: 2c8b0d6205f6 - main - net80211 / LinuxKPI 802.11: correct enum ieee80211_sta_rx_bw

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Tue, 07 Jan 2025 19:34:06 UTC
The branch main has been updated by bz:

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

commit 2c8b0d6205f6f98855773e3a82640b50abb2f2f6
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2024-12-29 08:07:48 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2025-01-07 19:32:44 +0000

    net80211 / LinuxKPI 802.11: correct enum ieee80211_sta_rx_bw
    
    When moving the enum from LinuxKPI to net80211 it got adjusted to be
    used in net80211 style in order to use it with a print_mask (%b).
    Turns out that change broke assumptions given the minimum value of
    BW_20 no longer was 0.  Adjust it back to a plain enum starting at 0
    and use an inline function to convert to value names.
    
    Pointy hat to:  bz
    Fixes:          ca389486a9599768e0ba69dca13c208020623083
    MFC after:      3 days
    Sponsored by:   The FreeBSD Foundation
    Reviewed by:    adrian
    Differential Revision: https://reviews.freebsd.org/D48375
---
 sys/net80211/ieee80211_ddb.c  |  4 ++--
 sys/net80211/ieee80211_ht.c   |  4 ++--
 sys/net80211/ieee80211_node.c |  4 ++--
 sys/net80211/ieee80211_node.h | 26 +++++++++++++++++++-------
 4 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/sys/net80211/ieee80211_ddb.c b/sys/net80211/ieee80211_ddb.c
index 0050038457c7..05b370eafa38 100644
--- a/sys/net80211/ieee80211_ddb.c
+++ b/sys/net80211/ieee80211_ddb.c
@@ -294,9 +294,9 @@ _db_show_sta(const struct ieee80211_node *ni)
 	db_printf("\thtcap %b htparam 0x%x htctlchan %u ht2ndchan %u\n",
 		ni->ni_htcap, IEEE80211_HTCAP_BITS,
 		ni->ni_htparam, ni->ni_htctlchan, ni->ni_ht2ndchan);
-	db_printf("\thtopmode 0x%x htstbc 0x%x chw %b\n",
+	db_printf("\thtopmode 0x%x htstbc 0x%x chw %d (%s)\n",
 		ni->ni_htopmode, ni->ni_htstbc,
-		ni->ni_chw, IEEE80211_NI_CHW_BITS);
+		ni->ni_chw, ieee80211_ni_chw_to_str(ni->ni_chw));
 
 	/* XXX ampdu state */
 	for (i = 0; i < WME_NUM_TID; i++)
diff --git a/sys/net80211/ieee80211_ht.c b/sys/net80211/ieee80211_ht.c
index 2ec5ffb1a2af..9e047244cc3b 100644
--- a/sys/net80211/ieee80211_ht.c
+++ b/sys/net80211/ieee80211_ht.c
@@ -2604,8 +2604,8 @@ ht_recv_action_ht_txchwidth(struct ieee80211_node *ni,
 	    IEEE80211_STA_RX_BW_40 : IEEE80211_STA_RX_BW_20;
 
 	IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_11N, ni,
-	    "%s: HT txchwidth, width %b%s",
-	    __func__, chw, IEEE80211_NI_CHW_BITS, ni->ni_chw != chw ? "*" : "");
+	    "%s: HT txchwidth, width %d%s (%s)", __func__,
+	    chw, ni->ni_chw != chw ? "*" : "", ieee80211_ni_chw_to_str(chw));
 	if (chw != ni->ni_chw) {
 		/* XXX does this need to change the ht40 station count? */
 		ni->ni_chw = chw;
diff --git a/sys/net80211/ieee80211_node.c b/sys/net80211/ieee80211_node.c
index d2a4558970f9..17ddc8533e41 100644
--- a/sys/net80211/ieee80211_node.c
+++ b/sys/net80211/ieee80211_node.c
@@ -2672,9 +2672,9 @@ ieee80211_dump_node(struct ieee80211_node_table *nt __unused,
 	printf("\thtcap %x htparam %x htctlchan %u ht2ndchan %u\n",
 		ni->ni_htcap, ni->ni_htparam,
 		ni->ni_htctlchan, ni->ni_ht2ndchan);
-	printf("\thtopmode %x htstbc %x htchw %b\n",
+	printf("\thtopmode %x htstbc %x htchw %d (%s)\n",
 		ni->ni_htopmode, ni->ni_htstbc,
-		ni->ni_chw, IEEE80211_NI_CHW_BITS);
+		ni->ni_chw, ieee80211_ni_chw_to_str(ni->ni_chw));
 	printf("\tvhtcap %x freq1 %d freq2 %d vhtbasicmcs %x\n",
 		ni->ni_vhtcap, (int) ni->ni_vht_chan1, (int) ni->ni_vht_chan2,
 		(int) ni->ni_vht_basicmcs);
diff --git a/sys/net80211/ieee80211_node.h b/sys/net80211/ieee80211_node.h
index 1f36ceb368b9..0039c743544c 100644
--- a/sys/net80211/ieee80211_node.h
+++ b/sys/net80211/ieee80211_node.h
@@ -115,17 +115,29 @@ enum ieee80211_mesh_mlstate {
  * flags. This allows us to keep the uint8_t slot for ni_chw in
  * struct ieee80211_node and means we do not have to sync to the value for
  * LinuxKPI.
+ *
+ * NB: BW_20 needs to 0 and values need to be sorted!  Cannot make it
+ * bitfield-alike for use with %b.
  */
 enum ieee80211_sta_rx_bw {
-	IEEE80211_STA_RX_BW_20		= 0x01,
-	IEEE80211_STA_RX_BW_40		= 0x02,
-	IEEE80211_STA_RX_BW_80		= 0x04,
-	IEEE80211_STA_RX_BW_160		= 0x08,
-	IEEE80211_STA_RX_BW_320		= 0x10,
+	IEEE80211_STA_RX_BW_20		= 0x00,
+	IEEE80211_STA_RX_BW_40,
+	IEEE80211_STA_RX_BW_80,
+	IEEE80211_STA_RX_BW_160,
+	IEEE80211_STA_RX_BW_320,
 } __packed;
 
-#define	IEEE80211_NI_CHW_BITS \
-	"\20\1BW_20\2BW_40\3BW_80\4BW_160\5BW_320"
+static inline const char *
+ieee80211_ni_chw_to_str(enum ieee80211_sta_rx_bw bw)
+{
+	switch (bw) {
+	case IEEE80211_STA_RX_BW_20:	return ("BW_20");
+	case IEEE80211_STA_RX_BW_40:	return ("BW_40");
+	case IEEE80211_STA_RX_BW_80:	return ("BW_80");
+	case IEEE80211_STA_RX_BW_160:	return ("BW_160");
+	case IEEE80211_STA_RX_BW_320:	return ("BW_320");
+	}
+}
 
 /*
  * Node specific information.  Note that drivers are expected