git: 013e516dc9b1 - main - LinuxKPI: 802.11: fix iwlwifi fw assert with older chipsets

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Sat, 11 Jun 2022 13:02:02 UTC
The branch main has been updated by bz:

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

commit 013e516dc9b1b32e9422ab02a875a05fc2d32f39
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-06-11 12:49:40 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-06-11 12:49:40 +0000

    LinuxKPI: 802.11: fix iwlwifi fw assert with older chipsets
    
    A problem which showed up on 13.1 between BETA3 and RC1 was that on older
    chipsets the fw would crash.  While some 0x18 ADD_STA problems were seen
    before, d9f59799fc3e was the actual trigger for this problem
    (in 0x28 MAC_CONTEXT command) in a squashed merge to the releng branch.
    Strangely there were no changes to assoc_to_run in that revision so other
    circumstances may be the actual cause but swapping the bss_info update and
    the sta_state in that function seem to make my 8265 happy while AX200 and
    AX210 stay good.
    
    Thanks to everyone who helped debug this.
    
    Sponsored by:   The FreeBSD Foundation (partially)
    MFC after:      3 days
---
 sys/compat/linuxkpi/common/src/linux_80211.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c
index a0cb20cf9032..4b473bfe2314 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211.c
@@ -1509,23 +1509,14 @@ lkpi_sta_assoc_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int
 	vif = LVIF_TO_VIF(lvif);
 
 	IEEE80211_UNLOCK(vap->iv_ic);
-	ni = NULL;
 
 	IMPROVE("ponder some of this moved to ic_newassoc, scan_assoc_success, "
 	    "and to lesser extend ieee80211_notify_node_join");
 
-	/* Finish assoc. */
-	/* Update sta_state (AUTH to ASSOC) and set aid. */
 	ni = ieee80211_ref_node(vap->iv_bss);
 	lsta = ni->ni_drv_data;
 	KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
-	KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not "
-	    "AUTH: %#x\n", __func__, lsta, lsta->state));
 	sta = LSTA_TO_STA(lsta);
-	sta->aid = IEEE80211_NODE_AID(ni);
-	error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_ASSOC);
-	if (error != 0)
-		goto out;
 
 	IMPROVE("wme / conf_tx [all]");
 
@@ -1559,6 +1550,16 @@ lkpi_sta_assoc_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int
 
 	lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
 
+	/* This MUST come after the bss_info_changed. */
+	/* Finish assoc. */
+	/* Update sta_state (AUTH to ASSOC) and set aid. */
+	KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not "
+	    "AUTH: %#x\n", __func__, lsta, lsta->state));
+	sta->aid = IEEE80211_NODE_AID(ni);
+	error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_ASSOC);
+	if (error != 0)
+		goto out;
+
 	/* - change_chanctx (if needed)
 	 * - event_callback
 	 */