Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Feb 2025 19:31:37 GMT
From:      Adrian Chadd <adrian@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 46de4d9fc21d - main - net80211: change ieee80211_ratectl_rate() to not return a rix
Message-ID:  <202502261931.51QJVbih017544@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by adrian:

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

commit 46de4d9fc21dfd8945e95135f607ba4fdfdf3d78
Author:     Adrian Chadd <adrian@FreeBSD.org>
AuthorDate: 2025-01-12 15:48:59 +0000
Commit:     Adrian Chadd <adrian@FreeBSD.org>
CommitDate: 2025-02-26 19:29:36 +0000

    net80211: change ieee80211_ratectl_rate() to not return a rix
    
    There are only a few places where the returned rix is used:
    
    * linuxkpi - logging
    * bwi/bwn - used for finding a fallback rate to choose, which
      honestly should be returned by the ratectl API
    * iwm - building the rateset to program into firmware
    
    Everyone else uses the dot11rate value in ni->ni_txnode.
    
    This is a precursor for VHT and later rate support; where currently
    there aren't rate tables in ieee80211_phy.c for VHT and later
    rates.
    
    Although it's likely doable to add tables for VHT, 11ax and MU-OFDMA
    (HE) rates are sufficiently larger/different to just not fit in the
    current scheme without more refactoring.
    
    Differential Revision:  https://reviews.freebsd.org/D48603
    Reviewed by:    bz, thj
---
 sys/compat/linuxkpi/common/src/linux_80211.c |  7 +++---
 sys/dev/bwi/if_bwi.c                         | 13 ++++-------
 sys/dev/bwn/if_bwn.c                         | 12 ++++-------
 sys/dev/iwm/if_iwm.c                         | 32 ++++++++++++++++++++++------
 sys/net80211/ieee80211_ratectl.h             |  4 ++--
 5 files changed, 39 insertions(+), 29 deletions(-)

diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c
index 72227378b097..14c7bab163b6 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211.c
@@ -6921,7 +6921,6 @@ linuxkpi_ieee80211_tx_status_ext(struct ieee80211_hw *hw,
 	}
 
 	if (ni != NULL) {
-		int ridx __unused;
 #ifdef LINUXKPI_DEBUG_80211
 		int old_rate;
 
@@ -6946,15 +6945,15 @@ linuxkpi_ieee80211_tx_status_ext(struct ieee80211_hw *hw,
 
 		IMPROVE("only update of rate matches but that requires us to get a proper rate");
 		ieee80211_ratectl_tx_complete(ni, &txs);
-		ridx = ieee80211_ratectl_rate(ni->ni_vap->iv_bss, NULL, 0);
+		ieee80211_ratectl_rate(ni->ni_vap->iv_bss, NULL, 0);
 
 #ifdef LINUXKPI_DEBUG_80211
 		if (linuxkpi_debug_80211 & D80211_TRACE_TX) {
-			printf("TX-RATE: %s: old %d new %d ridx %d, "
+			printf("TX-RATE: %s: old %d new %d "
 			    "long_retries %d\n", __func__,
 			    old_rate,
 			    ieee80211_node_get_txrate_dot11rate(ni->ni_vap->iv_bss),
-			    ridx, txs.long_retries);
+			    txs.long_retries);
 		}
 #endif
 	}
diff --git a/sys/dev/bwi/if_bwi.c b/sys/dev/bwi/if_bwi.c
index 079dac73ea43..1087ca813d65 100644
--- a/sys/dev/bwi/if_bwi.c
+++ b/sys/dev/bwi/if_bwi.c
@@ -2916,7 +2916,7 @@ bwi_encap(struct bwi_softc *sc, int idx, struct mbuf *m,
 	uint32_t mac_ctrl;
 	uint16_t phy_ctrl;
 	bus_addr_t paddr;
-	int type, ismcast, pkt_len, error, rix;
+	int type, ismcast, pkt_len, error;
 #if 0
 	const uint8_t *p;
 	int i;
@@ -2943,15 +2943,10 @@ bwi_encap(struct bwi_softc *sc, int idx, struct mbuf *m,
 	} else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) {
 		rate = rate_fb = tp->ucastrate;
 	} else {
-		rix = ieee80211_ratectl_rate(ni, NULL, pkt_len);
+		ieee80211_ratectl_rate(ni, NULL, pkt_len);
 		rate = ieee80211_node_get_txrate_dot11rate(ni);
-
-		if (rix > 0) {
-			rate_fb = ni->ni_rates.rs_rates[rix-1] &
-				  IEEE80211_RATE_VAL;
-		} else {
-			rate_fb = rate;
-		}
+		/* TODO: assign rate_fb the previous rate, if available */
+		rate_fb = rate;
 	}
 	tb->tb_rate[0] = rate;
 	tb->tb_rate[1] = rate_fb;
diff --git a/sys/dev/bwn/if_bwn.c b/sys/dev/bwn/if_bwn.c
index 571482afda70..38bf6f5d31a3 100644
--- a/sys/dev/bwn/if_bwn.c
+++ b/sys/dev/bwn/if_bwn.c
@@ -6394,7 +6394,7 @@ bwn_set_txhdr(struct bwn_mac *mac, struct ieee80211_node *ni,
 	uint8_t *prot_ptr;
 	unsigned int len;
 	uint32_t macctl = 0;
-	int rts_rate, rts_rate_fb, ismcast, isshort, rix, type;
+	int rts_rate, rts_rate_fb, ismcast, isshort, type;
 	uint16_t phyctl = 0;
 	uint8_t rate, rate_fb;
 	int fill_phy_ctl1 = 0;
@@ -6420,14 +6420,10 @@ bwn_set_txhdr(struct bwn_mac *mac, struct ieee80211_node *ni,
 	else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE)
 		rate = rate_fb = tp->ucastrate;
 	else {
-		rix = ieee80211_ratectl_rate(ni, NULL, 0);
+		ieee80211_ratectl_rate(ni, NULL, 0);
 		rate = ieee80211_node_get_txrate_dot11rate(ni);
-
-		if (rix > 0)
-			rate_fb = ni->ni_rates.rs_rates[rix - 1] &
-			    IEEE80211_RATE_VAL;
-		else
-			rate_fb = rate;
+		/* TODO: assign rate_fb the previous rate, if available */
+		rate_fb = rate;
 	}
 
 	sc->sc_tx_rate = rate;
diff --git a/sys/dev/iwm/if_iwm.c b/sys/dev/iwm/if_iwm.c
index bfe8c3635c7c..1e9090310ece 100644
--- a/sys/dev/iwm/if_iwm.c
+++ b/sys/dev/iwm/if_iwm.c
@@ -3502,11 +3502,11 @@ iwm_rx_tx_cmd_single(struct iwm_softc *sc, struct iwm_rx_packet *pkt,
 	if (rate_matched) {
 		ieee80211_ratectl_tx_complete(ni, txs);
 
-		int rix = ieee80211_ratectl_rate(vap->iv_bss, NULL, 0);
+		ieee80211_ratectl_rate(vap->iv_bss, NULL, 0);
 		new_rate = ieee80211_node_get_txrate_dot11rate(vap->iv_bss);
 		if (new_rate != 0 && new_rate != cur_rate) {
 			struct iwm_node *in = IWM_NODE(vap->iv_bss);
-			iwm_setrates(sc, in, rix);
+			iwm_setrates(sc, in, new_rate);
 			iwm_send_lq_cmd(sc, &in->in_lq, FALSE);
 		}
  	}
@@ -4270,7 +4270,7 @@ iwm_rate2ridx(struct iwm_softc *sc, uint8_t rate)
 
 
 static void
-iwm_setrates(struct iwm_softc *sc, struct iwm_node *in, int rix)
+iwm_setrates(struct iwm_softc *sc, struct iwm_node *in, int dot11rate)
 {
 	struct ieee80211_node *ni = &in->in_ni;
 	struct iwm_lq_cmd *lq = &in->in_lq;
@@ -4278,8 +4278,27 @@ iwm_setrates(struct iwm_softc *sc, struct iwm_node *in, int rix)
 	int nrates = rs->rs_nrates;
 	int i, ridx, tab = 0;
 //	int txant = 0;
+	int rix;
 
-	KASSERT(rix >= 0 && rix < nrates, ("invalid rix"));
+	/*
+	 * Look up the rate index for the given legacy rate from
+	 * the rs_rates table.  Default to the lowest rate if it's
+	 * not found (which is obviously hugely problematic.)
+	 */
+	rix = -1;
+	for (i = 0; i < nrates; i++) {
+		int rate = rs->rs_rates[i] & IEEE80211_RATE_VAL;
+		if (rate == dot11rate) {
+			rix = i;
+			break;
+		}
+	}
+	if (rix < 0) {
+		device_printf(sc->sc_dev,
+		    "%s: failed to lookup dot11rate (%d)\n",
+		    __func__, dot11rate);
+		rix = 0;
+	}
 
 	if (nrates > nitems(lq->rs_table)) {
 		device_printf(sc->sc_dev,
@@ -4559,8 +4578,9 @@ iwm_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
 		iwm_enable_beacon_filter(sc, ivp);
 		iwm_power_update_mac(sc);
 		iwm_update_quotas(sc, ivp);
-		int rix = ieee80211_ratectl_rate(&in->in_ni, NULL, 0);
-		iwm_setrates(sc, in, rix);
+		ieee80211_ratectl_rate(&in->in_ni, NULL, 0);
+		iwm_setrates(sc, in,
+		    ieee80211_node_get_txrate_dot11rate(&in->in_ni));
 
 		if ((error = iwm_send_lq_cmd(sc, &in->in_lq, TRUE)) != 0) {
 			device_printf(sc->sc_dev,
diff --git a/sys/net80211/ieee80211_ratectl.h b/sys/net80211/ieee80211_ratectl.h
index 2eae34763ed4..0e5beb5185cb 100644
--- a/sys/net80211/ieee80211_ratectl.h
+++ b/sys/net80211/ieee80211_ratectl.h
@@ -127,12 +127,12 @@ ieee80211_ratectl_node_deinit(struct ieee80211_node *ni)
 	vap->iv_rate->ir_node_deinit(ni);
 }
 
-static int __inline
+static void __inline
 ieee80211_ratectl_rate(struct ieee80211_node *ni, void *arg, uint32_t iarg)
 {
 	const struct ieee80211vap *vap = ni->ni_vap;
 
-	return vap->iv_rate->ir_rate(ni, arg, iarg);
+	vap->iv_rate->ir_rate(ni, arg, iarg);
 }
 
 static __inline void



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202502261931.51QJVbih017544>