Re: [PATCH mt76 2/7] wifi: mt76: mt7996: fix the behavior of radar detection

Shayne Chen
2025-12-12T08:35:47Z

On Tue, 2025-12-09 at 12:19 +0100, Lorenzo Bianconi wrote:
> On Nov 25, Shayne Chen wrote:
> > From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
> >
> > RDD_DET_MODE is a firmware command intended for testing and does
> > not
> > pause TX after radar detection, so remove it from the normal flow;
> > instead, use the MAC_ENABLE_CTRL firmware command to resume TX
> > after
> > the radar-triggered channel switch completes.
> >
> > Fixes: 1529e335f93d ("wifi: mt76: mt7996: rework radar HWRDD idx")
> > Co-developed-by: Shayne Chen <shayne.chen@mediatek.com>
> > Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
> > Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
> > ---
> >  .../net/wireless/mediatek/mt76/mt7996/mac.c   |  8 +---
> >  .../net/wireless/mediatek/mt76/mt7996/main.c  | 20 ++++++++
> >  .../net/wireless/mediatek/mt76/mt7996/mcu.c   | 46
> > ++++++++++++++++---
> >  .../net/wireless/mediatek/mt76/mt7996/mcu.h   |  1 +
> >  .../wireless/mediatek/mt76/mt7996/mt7996.h    |  2 +
> >  5 files changed, 65 insertions(+), 12 deletions(-)
> >
> >
> > diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
> > b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
> > index 7be03bbf34d4..c18c809ac77a 100644
> > --- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
> > +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
> > @@ -520,24 +520,32 @@ mt7996_mcu_rx_radar_detected(struct
> > mt7996_dev *dev, struct sk_buff *skb)
> >   break;
> >   case MT_RDD_IDX_BACKGROUND:
> >   if (!dev->rdd2_phy)
> > - return;
> > + goto err;
> >   mphy = dev->rdd2_phy->mt76;
> >   break;
> >   default:
> > - dev_err(dev->mt76.dev, "Unknown RDD idx %d\n", r-
> > >rdd_idx);
> > - return;
> > + goto err;
> >   }
> >
> >   if (!mphy)
> > - return;
> > + goto err;
> >
> > - if (r->rdd_idx == MT_RDD_IDX_BACKGROUND)
> > + if (r->rdd_idx == MT_RDD_IDX_BACKGROUND) {
> >   cfg80211_background_radar_event(mphy->hw->wiphy,
> >   &dev-
> > >rdd2_chandef,
> >   GFP_ATOMIC);
> > - else
> > + } else {
> > + struct mt7996_phy *phy = mphy->priv;
> > +
> > + phy->rdd_tx_paused = true;
> >   ieee80211_radar_detected(mphy->hw, NULL);
> > + }
> >   dev->hw_pattern++;
> > +
> > + return;
> > +
> > +err:
> > + dev_err(dev->mt76.dev, "Invalid RDD idx %d\n", r-
> > >rdd_idx);
> >  }
> >
> >  static void
> > @@ -4610,6 +4618,32 @@ int mt7996_mcu_set_radio_en(struct
> > mt7996_phy *phy, bool enable)
> >   &req, sizeof(req), true);
> >  }
> >
> > +int mt7996_mcu_rdd_resume_tx(struct mt7996_phy *phy)
> > +{
> > + struct {
> > + u8 band_idx;
> > + u8 _rsv[3];
> > +
> > + __le16 tag;
> > + __le16 len;
> > + u8 mac_enable;
> > + u8 _rsv2[3];
> > + } __packed req = {
> > + .band_idx = phy->mt76->band_idx,
> > + .tag =
> > cpu_to_le16(UNI_BAND_CONFIG_MAC_ENABLE_CTRL),
> > + .len = cpu_to_le16(sizeof(req) - 4),
> > + .mac_enable = 2,
> > + };
> > +
> > + if (!phy->rdd_tx_paused)
> > + return 0;
> > +
> > + phy->rdd_tx_paused = false;
>
> should you check the return value of mt76_mcu_send_msg() before
> setting
> rdd_tx_paused to false here?
>
> Regards,
> Lorenzo
>
Hi Lorenzo,

Yes, will post v2 to fix it.

Thanks,
Shayne
> > +
> > + return mt76_mcu_send_msg(&phy->dev->mt76,
> > MCU_WM_UNI_CMD(BAND_CONFIG),
> > + &req, sizeof(req), true);
> > +}
> > +
> >  int mt7996_mcu_rdd_cmd(struct mt7996_dev *dev, int cmd, u8
> > rdd_idx, u8 val)
> >  {
> >   struct {
> > diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
> > b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
> > index fc8b09e76f01..5b3597ca79be 100644
> > --- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
> > +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
> > @@ -835,6 +835,7 @@ enum {
> >  enum {
> >   UNI_BAND_CONFIG_RADIO_ENABLE,
> >   UNI_BAND_CONFIG_RTS_THRESHOLD = 0x08,
> > + UNI_BAND_CONFIG_MAC_ENABLE_CTRL = 0x0c,
> >  };
> >
> >  enum {
> > diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
> > b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
> > index 7a884311800e..d31864f973cc 100644
> > --- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
> > +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
> > @@ -377,6 +377,7 @@ struct mt7996_phy {
> >
> >   bool has_aux_rx;
> >   bool counter_reset;
> > + bool rdd_tx_paused;
> >  };
> >
> >  struct mt7996_dev {
> > @@ -726,6 +727,7 @@ int mt7996_mcu_get_temperature(struct
> > mt7996_phy *phy);
> >  int mt7996_mcu_set_thermal_throttling(struct mt7996_phy *phy, u8
> > state);
> >  int mt7996_mcu_set_thermal_protect(struct mt7996_phy *phy, bool
> > enable);
> >  int mt7996_mcu_set_txpower_sku(struct mt7996_phy *phy);
> > +int mt7996_mcu_rdd_resume_tx(struct mt7996_phy *phy);
> >  int mt7996_mcu_rdd_cmd(struct mt7996_dev *dev, int cmd, u8
> > rdd_idx, u8 val);
> >  int mt7996_mcu_rdd_background_enable(struct mt7996_phy *phy,
> >        struct cfg80211_chan_def
> > *chandef);
> > --
> > 2.51.0
> >