git: beaed0d4b5d0 - stable/13 - LinuxKPI: 802.11: make lkpi_ic_set_channel() unconditional

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Sun, 27 Mar 2022 20:14:12 UTC
The branch stable/13 has been updated by bz:

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

commit beaed0d4b5d0f901f78fc196f4b86d426a589792
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-03-24 16:51:02 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-03-27 18:12:23 +0000

    LinuxKPI: 802.11: make lkpi_ic_set_channel() unconditional
    
    For (*config)() based drivers not using chanctx we need to use
    ic_set_channel() to switch channels.  So far this was disabled
    based on scanning flags (as swscan is one of the initial use cases
    for this function).  Now make it only dependent on (*config)()
    for the moment to save us the work if (*config)() is not supported.
    
    For iwlwifi (*config)() is a NOP so no functional changes there
    but for other drivers such as rtw88 this will allow us to scan and
    set the channel (which helps to receive on channels other than 1).
    
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit b2cf3c2125bf6f34cb01296e7eda93f73bc4b715)
---
 sys/compat/linuxkpi/common/src/linux_80211.c | 103 ++++++++++++---------------
 1 file changed, 44 insertions(+), 59 deletions(-)

diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c
index e9e75488882a..fe4157212106 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211.c
@@ -2606,76 +2606,61 @@ lkpi_ic_set_channel(struct ieee80211com *ic)
 {
 	struct lkpi_hw *lhw;
 	struct ieee80211_hw *hw;
+	struct ieee80211_channel *c;
+	struct linuxkpi_ieee80211_channel *chan;
 	int error;
 
 	lhw = ic->ic_softc;
-#ifdef __no_longer__
-	/* For now only be concerned if scanning. */
-	if ((lhw->scan_flags & LKPI_SCAN_RUNNING) == 0) {
-		IMPROVE();
+
+	/* If we do not support (*config)() save us the work. */
+	if (lhw->ops->config == NULL)
+		return;
+
+	c = ic->ic_curchan;
+	if (c == NULL || c == IEEE80211_CHAN_ANYC) {
+		ic_printf(ic, "%s: c %p ops->config %p\n", __func__,
+		    c, lhw->ops->config);
 		return;
 	}
-#endif
 
-	if (ic->ic_flags_ext & IEEE80211_FEXT_SCAN_OFFLOAD) {
-		/*
-		 * AP scanning is taken care of by firmware, so only switch
-		 * channels in monitor mode (maybe, maybe not; to be
-		 * investigated at the right time).
-		 */
-		if (ic->ic_opmode == IEEE80211_M_MONITOR) {
-			UNIMPLEMENTED;
-		}
-	} else {
-		struct ieee80211_channel *c = ic->ic_curchan;
-		struct linuxkpi_ieee80211_channel *chan;
+	chan = lkpi_find_lkpi80211_chan(lhw, c);
+	if (chan == NULL) {
+		ic_printf(ic, "%s: c %p chan %p\n", __func__,
+		    c, chan);
+		return;
+	}
 
-		if (c == NULL || c == IEEE80211_CHAN_ANYC ||
-		    lhw->ops->config == NULL) {
-			ic_printf(ic, "%s: c %p ops->config %p\n", __func__,
-			    c, lhw->ops->config);
-			return;
-		}
+	/* XXX max power for scanning? */
+	IMPROVE();
 
-		chan = lkpi_find_lkpi80211_chan(lhw, c);
-		if (chan == NULL) {
-			ic_printf(ic, "%s: c %p chan %p\n", __func__,
-			    c, chan);
-			return;
-		}
+	hw = LHW_TO_HW(lhw);
+	cfg80211_chandef_create(&hw->conf.chandef, chan,
+	    NL80211_CHAN_NO_HT);
 
-		/* XXX max power for scanning? */
+	error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_CHANNEL);
+	if (error != 0 && error != EOPNOTSUPP) {
+		ic_printf(ic, "ERROR: %s: config %#0x returned %d\n",
+		    __func__, IEEE80211_CONF_CHANGE_CHANNEL, error);
+		/* XXX should we unroll to the previous chandef? */
 		IMPROVE();
+	} else {
+		/* Update radiotap channels as well. */
+		lhw->rtap_tx.wt_chan_freq = htole16(c->ic_freq);
+		lhw->rtap_tx.wt_chan_flags = htole16(c->ic_flags);
+		lhw->rtap_rx.wr_chan_freq = htole16(c->ic_freq);
+		lhw->rtap_rx.wr_chan_flags = htole16(c->ic_flags);
+	}
 
-		hw = LHW_TO_HW(lhw);
-		cfg80211_chandef_create(&hw->conf.chandef, chan,
-		    NL80211_CHAN_NO_HT);
-
-		error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_CHANNEL);
-		if (error != 0 && error != EOPNOTSUPP) {
-			ic_printf(ic, "ERROR: %s: config %#0x returned %d\n",
-			    __func__, IEEE80211_CONF_CHANGE_CHANNEL, error);
-			/* XXX should we unroll to the previous chandef? */
-			IMPROVE();
-		} else {
-			/* Update radiotap channels as well. */
-			lhw->rtap_tx.wt_chan_freq = htole16(c->ic_freq);
-			lhw->rtap_tx.wt_chan_flags = htole16(c->ic_flags);
-			lhw->rtap_rx.wr_chan_freq = htole16(c->ic_freq);
-			lhw->rtap_rx.wr_chan_flags = htole16(c->ic_flags);
-		}
-
-		/* Currently PS is hard coded off! Not sure it belongs here. */
-		IMPROVE();
-		if (ieee80211_hw_check(hw, SUPPORTS_PS) &&
-		    (hw->conf.flags & IEEE80211_CONF_PS) != 0) {
-			hw->conf.flags &= ~IEEE80211_CONF_PS;
-			error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_PS);
-			if (error != 0 && error != EOPNOTSUPP)
-				ic_printf(ic, "ERROR: %s: config %#0x returned "
-				    "%d\n", __func__, IEEE80211_CONF_CHANGE_PS,
-				    error);
-		}
+	/* Currently PS is hard coded off! Not sure it belongs here. */
+	IMPROVE();
+	if (ieee80211_hw_check(hw, SUPPORTS_PS) &&
+	    (hw->conf.flags & IEEE80211_CONF_PS) != 0) {
+		hw->conf.flags &= ~IEEE80211_CONF_PS;
+		error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_PS);
+		if (error != 0 && error != EOPNOTSUPP)
+			ic_printf(ic, "ERROR: %s: config %#0x returned "
+			    "%d\n", __func__, IEEE80211_CONF_CHANGE_PS,
+			    error);
 	}
 }