git: ada6a7cd6876 - stable/13 - LinuxKPI: 802.11 scan update

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Sun, 20 Feb 2022 18:15:46 UTC
The branch stable/13 has been updated by bz:

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

commit ada6a7cd68760603abb02adf4afd9ebbeaf7b4cf
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-02-16 03:00:34 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-02-20 16:25:19 +0000

    LinuxKPI: 802.11 scan update
    
    Realtek's rtw88 is returning a hard-coded 1 in case they cannot
    hw_scan (fw not advertising it).  In that case if we want any scan
    to run we need to fall-back to sw scan.  Start dealing with this.
    Long-term we probably need to keep internal state.
    
    (cherry picked from commit d3ef7fb459ff924911e5276db0c04b13cd8074d9)
---
 sys/compat/linuxkpi/common/src/linux_80211.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c
index 8e5e948db5fa..473c98317694 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211.c
@@ -1883,13 +1883,13 @@ lkpi_ic_scan_start(struct ieee80211com *ic)
 	ss = ic->ic_scan;
 	vap = ss->ss_vap;
 	if (vap->iv_state != IEEE80211_S_SCAN) {
-		/* Do not start a scan for now. */
+		IMPROVE("We need to be able to scan if not in S_SCAN");
 		return;
 	}
 
 	hw = LHW_TO_HW(lhw);
 	if ((ic->ic_flags_ext & IEEE80211_FEXT_SCAN_OFFLOAD) == 0) {
-
+sw_scan:
 		lvif = VAP_TO_LVIF(vap);
 		vif = LVIF_TO_VIF(lvif);
 
@@ -1949,6 +1949,10 @@ lkpi_ic_scan_start(struct ieee80211com *ic)
 		hw_req->req.ie_len = ;
 		hw_req->req.ie = ;
 #endif
+#if 0
+		hw->wiphy->max_scan_ie_len
+		hw->wiphy->max_scan_ssids
+#endif
 
 		hw_req->req.n_channels = nchan;
 		cpp = (struct linuxkpi_ieee80211_channel **)(hw_req + 1);
@@ -1994,12 +1998,21 @@ lkpi_ic_scan_start(struct ieee80211com *ic)
 		vif = LVIF_TO_VIF(lvif);
 		error = lkpi_80211_mo_hw_scan(hw, vif, hw_req);
 		if (error != 0) {
-			ic_printf(ic, "ERROR: %s: hw_scan returned %d\n",
-			    __func__, error);
-			ieee80211_cancel_scan(vap);
 			free(hw_req->ies.common_ies, M_80211_VAP);
 			free(hw_req, M_LKPI80211);
 			lhw->hw_req = NULL;
+
+			/*
+			 * XXX-SIGH magic number.
+			 * rtw88 has a magic "return 1" if offloading scan is
+			 * not possible.  Fall back to sw scan in that case.
+			 */
+			if (error == 1)
+				goto sw_scan;
+
+			ic_printf(ic, "ERROR: %s: hw_scan returned %d\n",
+			    __func__, error);
+			ieee80211_cancel_scan(vap);
 		}
 	}
 }