On Thu, Sep 17, 2026 at 08:00:05PM +0200, Robert Palm wrote:
> thanks again for the diagnosis (ADVANCED_SYSASSERT 0x20101A28, 20 vs
> 40 MHz channel width mismatch). Based on your explanation AI drafted
> a patch for me, and it would be great if you could take a look.

The AI did it wrong. Could you try this instead?


 handle dynamic channel width changes correctly in iwx(4)
 
 Avoids fatal firmware error ADVANCED_SYSASSERT 0x20101A28, where the
 fw station on a PHY has a higher Tx rate scaling bandwidth than the PHY.
 Thanks to Johannes Berg for explaining the firmware error code to me.
 
M  sys/dev/pci/if_iwx.c           |  53+  34-
M  sys/net80211/ieee80211_node.c  |  26+   0-
M  sys/net80211/ieee80211_node.h  |   2+   0-

3 files changed, 81 insertions(+), 34 deletions(-)

commit - 37e1413d351ba93bef8686ca531e826712a1b8c4
commit + 0f1b8e2a120b68de65f4012f6e114c8a1bbe233c
blob - 2bf28bd44809484fa4b228974c38199b1ff72df7
blob + 613a3c84228b22308ab95ca7f0ceebe4b98ab9ba
--- sys/dev/pci/if_iwx.c
+++ sys/dev/pci/if_iwx.c
@@ -3652,29 +3652,46 @@ iwx_phy_ctxt_task(void *arg)
        }
 
        chains = iwx_mimo_enabled(sc) ? 2 : 1;
-       if ((ni->ni_flags & IEEE80211_NODE_HT) &&
-           IEEE80211_CHAN_40MHZ_ALLOWED(ni->ni_chan) &&
-           ieee80211_node_supports_ht_chan40(ni))
-               sco = (ni->ni_htop0 & IEEE80211_HTOP0_SCO_MASK);
-       else
-               sco = IEEE80211_HTOP0_SCO_SCN;
-       if ((ni->ni_flags & IEEE80211_NODE_VHT) &&
-           IEEE80211_CHAN_160MHZ_ALLOWED(in->in_ni.ni_chan) &&
-           ieee80211_node_supports_vht_chan160(ni))
-               vht_chan_width = IEEE80211_VHTOP0_CHAN_WIDTH_160;
-       else if ((ni->ni_flags & IEEE80211_NODE_VHT) &&
-           IEEE80211_CHAN_80MHZ_ALLOWED(in->in_ni.ni_chan) &&
-           ieee80211_node_supports_vht_chan80(ni))
-               vht_chan_width = IEEE80211_VHTOP0_CHAN_WIDTH_80;
-       else
-               vht_chan_width = IEEE80211_VHTOP0_CHAN_WIDTH_HT;
+       sco = ieee80211_node_ht_secondary_channel_offset(ni);
+       vht_chan_width = ieee80211_node_vht_channel_width(ni);
        if (in->in_phyctxt->sco != sco ||
            in->in_phyctxt->vht_chan_width != vht_chan_width) {
+               int going_narrow = 0;
+
+               if ((sco == IEEE80211_HTOP0_SCO_SCN &&
+                   in->in_phyctxt->sco != IEEE80211_HTOP0_SCO_SCN) ||
+                   in->in_phyctxt->vht_chan_width > vht_chan_width)
+                       going_narrow = 1;
+
+               if (going_narrow) {
+                       /*
+                        * When channel bandwidth becomes narrower adjust
+                        * firmware Tx rates before setting new PHY context.
+                        */
+                       err = iwx_rs_init(sc, in);
+                       if (err) {
+                               printf("%s: failed to update rate scaling "
+                                   "(error %d)\n", DEVNAME(sc), err);
+                       }
+               }
+
                err = iwx_phy_ctxt_update(sc, in->in_phyctxt,
                    in->in_phyctxt->channel, chains, chains, 0, sco,
                    vht_chan_width);
                if (err)
                        printf("%s: failed to update PHY\n", DEVNAME(sc));
+
+               if (!going_narrow) {
+                       /*
+                        * When channel bandwidth becomes wider adjust
+                        * firmware Tx rates after setting the new PHY context.
+                        */
+                       err = iwx_rs_init(sc, in);
+                       if (err) {
+                               printf("%s: failed to update rate scaling "
+                                   "(error %d)\n", DEVNAME(sc), err);
+                       }
+               }
        }
 
        refcnt_rele_wake(&sc->task_refs);
@@ -8575,9 +8592,13 @@ iwx_rs_init_v3(struct iwx_softc *sc, struct iwx_node *
        uint32_t cmd_id;
        int i;
        size_t cmd_size = sizeof(cfg_cmd);
+       uint8_t sco, vht_chan_width;
 
        memset(&cfg_cmd, 0, sizeof(cfg_cmd));
 
+       sco = ieee80211_node_ht_secondary_channel_offset(ni);
+       vht_chan_width = ieee80211_node_vht_channel_width(ni);
+
        for (i = 0; i < rs->rs_nrates; i++) {
                uint8_t rval = rs->rs_rates[i] & IEEE80211_RATE_VAL;
                int idx = iwx_rs_rval2idx(rval);
@@ -8590,16 +8611,14 @@ iwx_rs_init_v3(struct iwx_softc *sc, struct iwx_node *
                cfg_cmd.mode = IWX_TLC_MNG_MODE_VHT;
                cfg_cmd.ht_rates[IWX_TLC_NSS_1][IWX_TLC_MCS_PER_BW_80] =
                    htole16(iwx_rs_vht_rates(sc, ni, 1));
-               if (in->in_phyctxt->vht_chan_width ==
-                   IEEE80211_VHTOP0_CHAN_WIDTH_160) {
+               if (vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160) {
                        cfg_cmd.ht_rates[IWX_TLC_NSS_1][IWX_TLC_MCS_PER_BW_160] 
=
                            
cfg_cmd.ht_rates[IWX_TLC_NSS_1][IWX_TLC_MCS_PER_BW_80];
                }
                if (iwx_mimo_enabled(sc)) {
                        cfg_cmd.ht_rates[IWX_TLC_NSS_2][IWX_TLC_MCS_PER_BW_80] =
                            htole16(iwx_rs_vht_rates(sc, ni, 2));
-                       if (in->in_phyctxt->vht_chan_width ==
-                           IEEE80211_VHTOP0_CHAN_WIDTH_160) {
+                       if (vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160) {
                                
cfg_cmd.ht_rates[IWX_TLC_NSS_2][IWX_TLC_MCS_PER_BW_160] =
                                    
cfg_cmd.ht_rates[IWX_TLC_NSS_2][IWX_TLC_MCS_PER_BW_80];
                        }
@@ -8619,14 +8638,13 @@ iwx_rs_init_v3(struct iwx_softc *sc, struct iwx_node *
 
        cfg_cmd.sta_id = IWX_STATION_ID;
        if ((ni->ni_flags & IEEE80211_NODE_VHT) &&
-           in->in_phyctxt->vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160)
+           vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160)
                cfg_cmd.max_ch_width = IWX_TLC_MNG_CH_WIDTH_160MHZ;
        else if ((ni->ni_flags & IEEE80211_NODE_VHT) &&
-           in->in_phyctxt->vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_80)
+           vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_80)
                cfg_cmd.max_ch_width = IWX_TLC_MNG_CH_WIDTH_80MHZ;
        else if ((ni->ni_flags & IEEE80211_NODE_HT) &&
-           (in->in_phyctxt->sco == IEEE80211_HTOP0_SCO_SCA ||
-           in->in_phyctxt->sco == IEEE80211_HTOP0_SCO_SCB))
+           (sco == IEEE80211_HTOP0_SCO_SCA || sco == IEEE80211_HTOP0_SCO_SCB))
                cfg_cmd.max_ch_width = IWX_TLC_MNG_CH_WIDTH_40MHZ;
        else
                cfg_cmd.max_ch_width = IWX_TLC_MNG_CH_WIDTH_20MHZ;
@@ -8662,7 +8680,7 @@ iwx_rs_init_v3(struct iwx_softc *sc, struct iwx_node *
            ieee80211_node_supports_vht_sgi80(ni))
                cfg_cmd.sgi_ch_width_supp |= (1 << IWX_TLC_MNG_CH_WIDTH_80MHZ);
        if ((ni->ni_flags & IEEE80211_NODE_VHT) &&
-           in->in_phyctxt->vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160 &&
+           vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160 &&
            ieee80211_node_supports_vht_sgi160(ni))
                cfg_cmd.sgi_ch_width_supp |= (1 << IWX_TLC_MNG_CH_WIDTH_160MHZ);
 
@@ -8679,9 +8697,13 @@ iwx_rs_init_v4(struct iwx_softc *sc, struct iwx_node *
        uint32_t cmd_id;
        int i;
        size_t cmd_size = sizeof(cfg_cmd);
+       uint8_t sco, vht_chan_width;
 
        memset(&cfg_cmd, 0, sizeof(cfg_cmd));
 
+       sco = ieee80211_node_ht_secondary_channel_offset(ni);
+       vht_chan_width = ieee80211_node_vht_channel_width(ni);
+
        for (i = 0; i < rs->rs_nrates; i++) {
                uint8_t rval = rs->rs_rates[i] & IEEE80211_RATE_VAL;
                int idx = iwx_rs_rval2idx(rval);
@@ -8694,16 +8716,14 @@ iwx_rs_init_v4(struct iwx_softc *sc, struct iwx_node *
                cfg_cmd.mode = IWX_TLC_MNG_MODE_VHT;
                cfg_cmd.ht_rates[IWX_TLC_NSS_1][IWX_TLC_MCS_PER_BW_80] =
                    htole16(iwx_rs_vht_rates(sc, ni, 1));
-               if (in->in_phyctxt->vht_chan_width ==
-                   IEEE80211_VHTOP0_CHAN_WIDTH_160) {
+               if (vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160) {
                        cfg_cmd.ht_rates[IWX_TLC_NSS_1][IWX_TLC_MCS_PER_BW_160] 
=
                            
cfg_cmd.ht_rates[IWX_TLC_NSS_1][IWX_TLC_MCS_PER_BW_80];
                }
                if (iwx_mimo_enabled(sc)) {
                        cfg_cmd.ht_rates[IWX_TLC_NSS_2][IWX_TLC_MCS_PER_BW_80] =
                            htole16(iwx_rs_vht_rates(sc, ni, 2));
-                       if (in->in_phyctxt->vht_chan_width ==
-                           IEEE80211_VHTOP0_CHAN_WIDTH_160) {
+                       if (vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160) {
                                
cfg_cmd.ht_rates[IWX_TLC_NSS_2][IWX_TLC_MCS_PER_BW_160] =
                                    
cfg_cmd.ht_rates[IWX_TLC_NSS_2][IWX_TLC_MCS_PER_BW_80];
                        }
@@ -8723,14 +8743,13 @@ iwx_rs_init_v4(struct iwx_softc *sc, struct iwx_node *
 
        cfg_cmd.sta_id = IWX_STATION_ID;
        if ((ni->ni_flags & IEEE80211_NODE_VHT) &&
-           in->in_phyctxt->vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160)
+           vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160)
                cfg_cmd.max_ch_width = IWX_TLC_MNG_CH_WIDTH_160MHZ;
        else if ((ni->ni_flags & IEEE80211_NODE_VHT) &&
-           in->in_phyctxt->vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_80)
+           vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_80)
                cfg_cmd.max_ch_width = IWX_TLC_MNG_CH_WIDTH_80MHZ;
        else if ((ni->ni_flags & IEEE80211_NODE_HT) &&
-           (in->in_phyctxt->sco == IEEE80211_HTOP0_SCO_SCA ||
-           in->in_phyctxt->sco == IEEE80211_HTOP0_SCO_SCB))
+           (sco == IEEE80211_HTOP0_SCO_SCA || sco == IEEE80211_HTOP0_SCO_SCB))
                cfg_cmd.max_ch_width = IWX_TLC_MNG_CH_WIDTH_40MHZ;
        else
                cfg_cmd.max_ch_width = IWX_TLC_MNG_CH_WIDTH_20MHZ;
@@ -8766,7 +8785,7 @@ iwx_rs_init_v4(struct iwx_softc *sc, struct iwx_node *
            ieee80211_node_supports_vht_sgi80(ni))
                cfg_cmd.sgi_ch_width_supp |= (1 << IWX_TLC_MNG_CH_WIDTH_80MHZ);
        if ((ni->ni_flags & IEEE80211_NODE_VHT) &&
-           in->in_phyctxt->vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160 &&
+           vht_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160 &&
            ieee80211_node_supports_vht_sgi160(ni))
                cfg_cmd.sgi_ch_width_supp |= (1 << IWX_TLC_MNG_CH_WIDTH_160MHZ);
 
blob - 5038e611ddcc80496bae94fe6008a7f2a5945949
blob + 4e02b216d464c88208994df43cfa8200c23e03a5
--- sys/net80211/ieee80211_node.c
+++ sys/net80211/ieee80211_node.c
@@ -2448,6 +2448,32 @@ ieee80211_clear_htcaps(struct ieee80211_node *ni)
 }
 #endif
 
+uint8_t
+ieee80211_node_ht_secondary_channel_offset(struct ieee80211_node *ni)
+{
+       if ((ni->ni_flags & IEEE80211_NODE_HT) &&
+           IEEE80211_CHAN_40MHZ_ALLOWED(ni->ni_chan) &&
+           ieee80211_node_supports_ht_chan40(ni))
+               return (ni->ni_htop0 & IEEE80211_HTOP0_SCO_MASK);
+       else
+               return IEEE80211_HTOP0_SCO_SCN;
+}
+
+uint8_t
+ieee80211_node_vht_channel_width(struct ieee80211_node *ni)
+{
+       if ((ni->ni_flags & IEEE80211_NODE_VHT) &&
+           IEEE80211_CHAN_160MHZ_ALLOWED(ni->ni_chan) &&
+           ieee80211_node_supports_vht_chan160(ni))
+               return IEEE80211_VHTOP0_CHAN_WIDTH_160;
+       else if ((ni->ni_flags & IEEE80211_NODE_VHT) &&
+           IEEE80211_CHAN_80MHZ_ALLOWED(ni->ni_chan) &&
+           ieee80211_node_supports_vht_chan80(ni))
+               return IEEE80211_VHTOP0_CHAN_WIDTH_80;
+       else
+               return IEEE80211_VHTOP0_CHAN_WIDTH_HT;
+}
+
 int
 ieee80211_40mhz_valid_secondary_above(uint8_t primary_chan)
 {
blob - dcb9e40e8345da7918b9793f1428156d60ac0e07
blob + b058bf7fc79ab09ed3ace8debfcb802ed56b0f8c
--- sys/net80211/ieee80211_node.h
+++ sys/net80211/ieee80211_node.h
@@ -678,6 +678,8 @@ void ieee80211_clean_nodes(struct ieee80211com *, int)
 void ieee80211_setup_htcaps(struct ieee80211_node *, const uint8_t *,
     uint8_t);
 void ieee80211_clear_htcaps(struct ieee80211_node *);
+uint8_t ieee80211_node_ht_secondary_channel_offset(struct ieee80211_node *);
+uint8_t ieee80211_node_vht_channel_width(struct ieee80211_node *);
 int ieee80211_setup_htop(struct ieee80211_node *, const uint8_t *,
     uint8_t, int);
 void ieee80211_setup_vhtcaps(struct ieee80211_node *, const uint8_t *,

Reply via email to