git: ca389486a959 - main - net80211 / LinuxKPI 802.11: use enum ieee80211_sta_rx_bw for ni_chw
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 08 Dec 2024 20:58:57 UTC
The branch main has been updated by bz:
URL: https://cgit.FreeBSD.org/src/commit/?id=ca389486a9599768e0ba69dca13c208020623083
commit ca389486a9599768e0ba69dca13c208020623083
Author: Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2024-12-03 17:43:38 +0000
Commit: Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2024-12-08 20:57:53 +0000
net80211 / LinuxKPI 802.11: use enum ieee80211_sta_rx_bw for ni_chw
net80211 node ni_chw currently encodes the channel width as Mhz number.
LinuxKPI 802.11 uses enum ieee80211_sta_rx_bw for the same.
Rather than keeping the "20" and "40" throughout the code (eventually
expanded to 80/160/320) switch them over to use the enum throughout
and add a print mask for debug output. While designed as bitmask it
is not supposed to be used as such; the bitmask is only used to be
able to use %b with a print mask.
Once we get to 320Mhz channel widths we would otherwise also need to
extend the uint8_t in struct ieee80211_node; making
enum ieee80211_sta_rx_bw __packed allows us for three more channel
widths without breaking the KBI (if we were not to use %b with a
print_mask but use a lookup function for the string we could extend
it for a long time).
Sponsored by: The FreeBSD Foundation
MFC after: 14 days
Reviewed by: adrian
Differential Revision: https://reviews.freebsd.org/D47891
---
.../linuxkpi/common/include/linux/ieee80211.h | 8 --------
sys/dev/ath/ath_rate/sample/sample.c | 8 ++++----
sys/dev/ath/if_ath_tx_ht.c | 6 +++---
sys/dev/mwl/if_mwl.c | 2 +-
sys/net80211/ieee80211_ddb.c | 5 +++--
sys/net80211/ieee80211_ht.c | 20 +++++++++++---------
sys/net80211/ieee80211_node.c | 7 ++++---
sys/net80211/ieee80211_node.h | 21 ++++++++++++++++++++-
sys/net80211/ieee80211_sta.c | 2 +-
9 files changed, 47 insertions(+), 32 deletions(-)
diff --git a/sys/compat/linuxkpi/common/include/linux/ieee80211.h b/sys/compat/linuxkpi/common/include/linux/ieee80211.h
index 865d85c6f7b7..58ebbcfe0097 100644
--- a/sys/compat/linuxkpi/common/include/linux/ieee80211.h
+++ b/sys/compat/linuxkpi/common/include/linux/ieee80211.h
@@ -387,14 +387,6 @@ enum ieee80211_sta_state {
IEEE80211_STA_AUTHORIZED = 4, /* 802.1x */
};
-enum ieee80211_sta_rx_bw {
- IEEE80211_STA_RX_BW_20,
- IEEE80211_STA_RX_BW_40,
- IEEE80211_STA_RX_BW_80,
- IEEE80211_STA_RX_BW_160,
- IEEE80211_STA_RX_BW_320,
-};
-
enum ieee80211_tx_info_flags {
/* XXX TODO .. right shift numbers - not sure where that came from? */
IEEE80211_TX_CTL_AMPDU = BIT(0),
diff --git a/sys/dev/ath/ath_rate/sample/sample.c b/sys/dev/ath/ath_rate/sample/sample.c
index 8e70699f708d..58eea8f64993 100644
--- a/sys/dev/ath/ath_rate/sample/sample.c
+++ b/sys/dev/ath/ath_rate/sample/sample.c
@@ -179,7 +179,7 @@ ath_rate_sample_find_min_pktlength(struct ath_softc *sc,
const struct txschedule *sched = &sn->sched[rix0];
int max_pkt_length = 65530; // ATH_AGGR_MAXSIZE
// Note: this may not be true in all cases; need to check?
- int is_ht40 = (an->an_node.ni_chw == 40);
+ int is_ht40 = (an->an_node.ni_chw == IEEE80211_STA_RX_BW_40);
// Note: not great, but good enough..
int idx = is_ht40 ? MCS_HT40 : MCS_HT20;
@@ -973,7 +973,7 @@ update_stats(struct ath_softc *sc, struct ath_node *an,
const int size_bin = size_to_bin(frame_size);
const int size = bin_to_size(size_bin);
int tt;
- int is_ht40 = (an->an_node.ni_chw == 40);
+ int is_ht40 = (an->an_node.ni_chw == IEEE80211_STA_RX_BW_40);
int pct;
if (!IS_RATE_DEFINED(sn, rix0))
@@ -1359,7 +1359,7 @@ ath_rate_ctl_reset(struct ath_softc *sc, struct ieee80211_node *ni)
continue;
printf(" %d %s/%d", dot11rate(rt, rix), dot11rate_label(rt, rix),
calc_usecs_unicast_packet(sc, 1600, rix, 0,0,
- (ni->ni_chw == 40)));
+ (ni->ni_chw == IEEE80211_STA_RX_BW_40)));
}
printf("\n");
}
@@ -1390,7 +1390,7 @@ ath_rate_ctl_reset(struct ath_softc *sc, struct ieee80211_node *ni)
sn->stats[y][rix].perfect_tx_time =
calc_usecs_unicast_packet(sc, size, rix, 0, 0,
- (ni->ni_chw == 40));
+ (ni->ni_chw == IEEE80211_STA_RX_BW_40));
sn->stats[y][rix].average_tx_time =
sn->stats[y][rix].perfect_tx_time;
}
diff --git a/sys/dev/ath/if_ath_tx_ht.c b/sys/dev/ath/if_ath_tx_ht.c
index 9558b7c9e696..ac61c7b4cf54 100644
--- a/sys/dev/ath/if_ath_tx_ht.c
+++ b/sys/dev/ath/if_ath_tx_ht.c
@@ -283,7 +283,7 @@ ath_tx_rate_fill_rcflags(struct ath_softc *sc, struct ath_buf *bf)
if (IS_HT_RATE(rate)) {
rc[i].flags |= ATH_RC_HT_FLAG;
- if (ni->ni_chw == 40)
+ if (ni->ni_chw == IEEE80211_STA_RX_BW_40)
rc[i].flags |= ATH_RC_CW40_FLAG;
/*
@@ -295,13 +295,13 @@ ath_tx_rate_fill_rcflags(struct ath_softc *sc, struct ath_buf *bf)
* and doesn't return the fractional part, so
* we are always "out" by some amount.
*/
- if (ni->ni_chw == 40 &&
+ if (ni->ni_chw == IEEE80211_STA_RX_BW_40 &&
ieee80211_ht_check_tx_shortgi_40(ni) &&
(bf->bf_flags & ATH_BUF_TOA_PROBE) == 0) {
rc[i].flags |= ATH_RC_SGI_FLAG;
}
- if (ni->ni_chw == 20 &&
+ if (ni->ni_chw == IEEE80211_STA_RX_BW_40 &&
ieee80211_ht_check_tx_shortgi_20(ni) &&
(bf->bf_flags & ATH_BUF_TOA_PROBE) == 0) {
rc[i].flags |= ATH_RC_SGI_FLAG;
diff --git a/sys/dev/mwl/if_mwl.c b/sys/dev/mwl/if_mwl.c
index f396ef7256f4..d0d13e576d31 100644
--- a/sys/dev/mwl/if_mwl.c
+++ b/sys/dev/mwl/if_mwl.c
@@ -4016,7 +4016,7 @@ mkpeerinfo(MWL_HAL_PEERINFO *pi, const struct ieee80211_node *ni)
pi->HTCapabilitiesInfo &= ~IEEE80211_HTCAP_SHORTGI40;
if ((vap->iv_flags_ht & IEEE80211_FHT_SHORTGI20) == 0)
pi->HTCapabilitiesInfo &= ~IEEE80211_HTCAP_SHORTGI20;
- if (ni->ni_chw != 40)
+ if (ni->ni_chw != IEEE80211_STA_RX_BW_40)
pi->HTCapabilitiesInfo &= ~IEEE80211_HTCAP_CHWIDTH40;
}
return pi;
diff --git a/sys/net80211/ieee80211_ddb.c b/sys/net80211/ieee80211_ddb.c
index eca893fa6810..0050038457c7 100644
--- a/sys/net80211/ieee80211_ddb.c
+++ b/sys/net80211/ieee80211_ddb.c
@@ -294,8 +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 %u\n",
- ni->ni_htopmode, ni->ni_htstbc, ni->ni_chw);
+ db_printf("\thtopmode 0x%x htstbc 0x%x chw %b\n",
+ ni->ni_htopmode, ni->ni_htstbc,
+ ni->ni_chw, IEEE80211_NI_CHW_BITS);
/* 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 1f97b7b9927a..293b5be20d32 100644
--- a/sys/net80211/ieee80211_ht.c
+++ b/sys/net80211/ieee80211_ht.c
@@ -1473,7 +1473,7 @@ ieee80211_ht_wds_init(struct ieee80211_node *ni)
ni->ni_htcap |= IEEE80211_HTCAP_SHORTGI20;
if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) {
ni->ni_htcap |= IEEE80211_HTCAP_CHWIDTH40;
- ni->ni_chw = 40;
+ ni->ni_chw = IEEE80211_STA_RX_BW_40;
if (IEEE80211_IS_CHAN_HT40U(ni->ni_chan))
ni->ni_ht2ndchan = IEEE80211_HTINFO_2NDCHAN_ABOVE;
else if (IEEE80211_IS_CHAN_HT40D(ni->ni_chan))
@@ -1481,7 +1481,7 @@ ieee80211_ht_wds_init(struct ieee80211_node *ni)
if (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI40)
ni->ni_htcap |= IEEE80211_HTCAP_SHORTGI40;
} else {
- ni->ni_chw = 20;
+ ni->ni_chw = IEEE80211_STA_RX_BW_20;
ni->ni_ht2ndchan = IEEE80211_HTINFO_2NDCHAN_NONE;
}
ni->ni_htctlchan = ni->ni_chan->ic_ieee;
@@ -1577,7 +1577,7 @@ ieee80211_ht_node_join(struct ieee80211_node *ni)
if (ni->ni_flags & IEEE80211_NODE_HT) {
vap->iv_ht_sta_assoc++;
- if (ni->ni_chw == 40)
+ if (ni->ni_chw == IEEE80211_STA_RX_BW_40)
vap->iv_ht40_sta_assoc++;
}
htinfo_update(vap);
@@ -1595,7 +1595,7 @@ ieee80211_ht_node_leave(struct ieee80211_node *ni)
if (ni->ni_flags & IEEE80211_NODE_HT) {
vap->iv_ht_sta_assoc--;
- if (ni->ni_chw == 40)
+ if (ni->ni_chw == IEEE80211_STA_RX_BW_40)
vap->iv_ht40_sta_assoc--;
}
htinfo_update(vap);
@@ -1823,7 +1823,8 @@ htinfo_update_chw(struct ieee80211_node *ni, int htflags, int vhtflags)
done:
/* update node's (11n) tx channel width */
- ni->ni_chw = IEEE80211_IS_CHAN_HT40(ni->ni_chan)? 40 : 20;
+ ni->ni_chw = IEEE80211_IS_CHAN_HT40(ni->ni_chan) ?
+ IEEE80211_STA_RX_BW_40 : IEEE80211_STA_RX_BW_20;
return (ret);
}
@@ -2599,11 +2600,12 @@ ht_recv_action_ht_txchwidth(struct ieee80211_node *ni,
{
int chw;
- chw = (frm[2] == IEEE80211_A_HT_TXCHWIDTH_2040) ? 40 : 20;
+ chw = (frm[2] == IEEE80211_A_HT_TXCHWIDTH_2040) ?
+ 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 %d%s",
- __func__, chw, ni->ni_chw != chw ? "*" : "");
+ "%s: HT txchwidth, width %b%s",
+ __func__, chw, IEEE80211_NI_CHW_BITS, ni->ni_chw != chw ? "*" : "");
if (chw != ni->ni_chw) {
/* XXX does this need to change the ht40 station count? */
ni->ni_chw = chw;
@@ -3742,5 +3744,5 @@ ieee80211_ht_check_tx_ht40(const struct ieee80211_node *ni)
return (IEEE80211_IS_CHAN_HT40(bss_chan) &&
IEEE80211_IS_CHAN_HT40(ni->ni_chan) &&
- (ni->ni_chw == 40));
+ (ni->ni_chw == IEEE80211_STA_RX_BW_40));
}
diff --git a/sys/net80211/ieee80211_node.c b/sys/net80211/ieee80211_node.c
index 8f8dc5f378b8..d2a4558970f9 100644
--- a/sys/net80211/ieee80211_node.c
+++ b/sys/net80211/ieee80211_node.c
@@ -2672,8 +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 %u\n",
- ni->ni_htopmode, ni->ni_htstbc, ni->ni_chw);
+ printf("\thtopmode %x htstbc %x htchw %b\n",
+ ni->ni_htopmode, ni->ni_htstbc,
+ ni->ni_chw, IEEE80211_NI_CHW_BITS);
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);
@@ -2831,7 +2832,7 @@ ieee80211_node_join(struct ieee80211_node *ni, int resp)
ni->ni_flags & IEEE80211_NODE_QOS ? ", QoS" : "",
/* XXX update for VHT string */
ni->ni_flags & IEEE80211_NODE_HT ?
- (ni->ni_chw == 40 ? ", HT40" : ", HT20") : "",
+ (ni->ni_chw == IEEE80211_STA_RX_BW_40 ? ", HT40" : ", HT20") : "",
ni->ni_flags & IEEE80211_NODE_AMPDU ? " (+AMPDU)" : "",
ni->ni_flags & IEEE80211_NODE_AMSDU ? " (+AMSDU)" : "",
ni->ni_flags & IEEE80211_NODE_MIMO_RTS ? " (+SMPS-DYN)" :
diff --git a/sys/net80211/ieee80211_node.h b/sys/net80211/ieee80211_node.h
index 954e8e03563f..1f36ceb368b9 100644
--- a/sys/net80211/ieee80211_node.h
+++ b/sys/net80211/ieee80211_node.h
@@ -108,6 +108,25 @@ enum ieee80211_mesh_mlstate {
#define IEEE80211_MESH_MLSTATE_BITS \
"\20\1IDLE\2OPENSNT\2OPENRCV\3CONFIRMRCV\4ESTABLISHED\5HOLDING"
+/*
+ * This structure is shared with LinuxKPI 802.11 code describing up-to
+ * which channel width the station can receive.
+ * Rather than using hardcoded MHz values for the channel width use an enum with
+ * 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.
+ */
+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,
+} __packed;
+
+#define IEEE80211_NI_CHW_BITS \
+ "\20\1BW_20\2BW_40\3BW_80\4BW_160\5BW_320"
+
/*
* Node specific information. Note that drivers are expected
* to derive from this structure to add device-specific per-node
@@ -222,7 +241,7 @@ struct ieee80211_node {
uint8_t ni_ht2ndchan; /* HT 2nd channel */
uint8_t ni_htopmode; /* HT operating mode */
uint8_t ni_htstbc; /* HT */
- uint8_t ni_chw; /* negotiated channel width */
+ enum ieee80211_sta_rx_bw ni_chw; /* negotiated channel width */
struct ieee80211_htrateset ni_htrates; /* negotiated ht rate set */
struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_TID];
struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID];
diff --git a/sys/net80211/ieee80211_sta.c b/sys/net80211/ieee80211_sta.c
index 97ed52295d6d..ca06546abdb9 100644
--- a/sys/net80211/ieee80211_sta.c
+++ b/sys/net80211/ieee80211_sta.c
@@ -1937,7 +1937,7 @@ sta_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0, int subtype,
vap->iv_flags&IEEE80211_F_USEPROT ? ", protection" : "",
ni->ni_flags & IEEE80211_NODE_QOS ? ", QoS" : "",
ni->ni_flags & IEEE80211_NODE_HT ?
- (ni->ni_chw == 40 ? ", HT40" : ", HT20") : "",
+ (ni->ni_chw == IEEE80211_STA_RX_BW_40 ? ", HT40" : ", HT20") : "",
ni->ni_flags & IEEE80211_NODE_AMPDU ? " (+AMPDU)" : "",
ni->ni_flags & IEEE80211_NODE_AMSDU ? " (+AMSDU)" : "",
ni->ni_flags & IEEE80211_NODE_MIMO_RTS ? " (+SMPS-DYN)" :