Linux wireless drivers development
 help / color / mirror / Atom feed
From: Ping-Ke Shih <pkshih@realtek.com>
To: <linux-wireless@vger.kernel.org>
Cc: <ku920601@realtek.com>, <damon.chen@realtek.com>,
	<phhuang@realtek.com>, <kevin_yang@realtek.com>
Subject: [PATCH rtw-next 07/11] wifi: rtw89: get default channel based on supported bands
Date: Thu, 12 Nov 2026 14:05:56 +0800	[thread overview]
Message-ID: <20261112060600.71784-8-pkshih@realtek.com> (raw)
In-Reply-To: <20261112060600.71784-1-pkshih@realtek.com>

From: Zong-Zhe Yang <kevin_yang@realtek.com>

Previously, because all chipsets support 2 GHz, default channel was
always one of 2 GHz. However, after adding RTW89_QUIRK_DISABLE_2GHZ,
wiphy might not really register NL80211_BAND_2GHZ.

Refine logic to get default channel based on bitmap of supported bands.
Besides, throw an error if there is no any supported bands to use.

Fixes: 355626a2c232 ("wifi: rtw89: 8852cu: add quirk to disable 2.4 GHz band")
Signed-off-by: Zong-Zhe Yang <kevin_yang@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
---
 drivers/net/wireless/realtek/rtw89/chan.c | 15 +++++++----
 drivers/net/wireless/realtek/rtw89/chan.h |  2 +-
 drivers/net/wireless/realtek/rtw89/core.c | 32 ++++++++++++++++++++---
 drivers/net/wireless/realtek/rtw89/core.h |  2 +-
 4 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw89/chan.c b/drivers/net/wireless/realtek/rtw89/chan.c
index a7ba47bd9abd..6a4ea1c3f9ca 100644
--- a/drivers/net/wireless/realtek/rtw89/chan.c
+++ b/drivers/net/wireless/realtek/rtw89/chan.c
@@ -293,15 +293,20 @@ void rtw89_config_roc_chandef(struct rtw89_dev *rtwdev,
 	}
 }
 
-static void rtw89_config_default_chandef(struct rtw89_dev *rtwdev)
+static int rtw89_config_default_chandef(struct rtw89_dev *rtwdev)
 {
-	struct cfg80211_chan_def chandef = {0};
+	struct cfg80211_chan_def chandef = {};
+	int ret;
+
+	ret = rtw89_get_default_chandef(rtwdev, &chandef);
+	if (ret)
+		return ret;
 
-	rtw89_get_default_chandef(&chandef);
 	__rtw89_config_entity_chandef(rtwdev, RTW89_CHANCTX_0, &chandef);
+	return 0;
 }
 
-void rtw89_entity_init(struct rtw89_dev *rtwdev)
+int rtw89_entity_init(struct rtw89_dev *rtwdev)
 {
 	struct rtw89_hal *hal = &rtwdev->hal;
 	struct rtw89_entity_mgnt *mgnt = &hal->entity_mgnt;
@@ -321,7 +326,7 @@ void rtw89_entity_init(struct rtw89_dev *rtwdev)
 
 	hal->entity_force_hw = RTW89_PHY_NUM;
 
-	rtw89_config_default_chandef(rtwdev);
+	return rtw89_config_default_chandef(rtwdev);
 }
 
 static bool rtw89_vif_is_active_role(struct rtw89_vif *rtwvif)
diff --git a/drivers/net/wireless/realtek/rtw89/chan.h b/drivers/net/wireless/realtek/rtw89/chan.h
index e9df90c4ce3c..509e64dfcd6d 100644
--- a/drivers/net/wireless/realtek/rtw89/chan.h
+++ b/drivers/net/wireless/realtek/rtw89/chan.h
@@ -172,7 +172,7 @@ void rtw89_config_entity_chandef(struct rtw89_dev *rtwdev,
 void rtw89_config_roc_chandef(struct rtw89_dev *rtwdev,
 			      struct rtw89_vif_link *rtwvif_link,
 			      const struct cfg80211_chan_def *chandef);
-void rtw89_entity_init(struct rtw89_dev *rtwdev);
+int rtw89_entity_init(struct rtw89_dev *rtwdev);
 enum rtw89_entity_mode rtw89_entity_recalc(struct rtw89_dev *rtwdev);
 bool rtw89_entity_check_hw(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy_idx);
 void rtw89_entity_force_hw(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy_idx);
diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c
index 4467ca25f1b0..1ef8cf5f2dfd 100644
--- a/drivers/net/wireless/realtek/rtw89/core.c
+++ b/drivers/net/wireless/realtek/rtw89/core.c
@@ -401,10 +401,30 @@ static void rtw89_traffic_stats_accu(struct rtw89_dev *rtwdev,
 	}
 }
 
-void rtw89_get_default_chandef(struct cfg80211_chan_def *chandef)
+static struct ieee80211_channel *rtw89_core_get_default_channel(struct rtw89_dev *rtwdev)
 {
-	cfg80211_chandef_create(chandef, &rtw89_channels_2ghz[0],
-				NL80211_CHAN_NO_HT);
+	if (test_bit(NL80211_BAND_2GHZ, rtwdev->supported_bands))
+		return &rtw89_channels_2ghz[0];
+	if (test_bit(NL80211_BAND_5GHZ, rtwdev->supported_bands))
+		return &rtw89_channels_5ghz[0];
+	if (test_bit(NL80211_BAND_6GHZ, rtwdev->supported_bands))
+		return &rtw89_channels_6ghz[0];
+
+	return NULL;
+}
+
+int rtw89_get_default_chandef(struct rtw89_dev *rtwdev, struct cfg80211_chan_def *chandef)
+{
+	struct ieee80211_channel *dflt;
+
+	dflt = rtw89_core_get_default_channel(rtwdev);
+	if (unlikely(!dflt)) {
+		rtw89_err(rtwdev, "no valid default channel\n");
+		return -EINVAL;
+	}
+
+	cfg80211_chandef_create(chandef, dflt, NL80211_CHAN_NO_HT);
+	return 0;
 }
 
 void rtw89_get_channel_params(const struct cfg80211_chan_def *chandef,
@@ -6987,6 +7007,7 @@ int rtw89_core_init(struct rtw89_dev *rtwdev)
 	const struct rtw89_mac_gen_def *mac = rtwdev->chip->mac_def;
 	struct rtw89_btc *btc = &rtwdev->btc;
 	u8 band;
+	int ret;
 
 	rtwdev->io = rtw89_fw_cmd_ofld_alloc_and_get_io_ops(rtwdev);
 
@@ -7062,8 +7083,11 @@ int rtw89_core_init(struct rtw89_dev *rtwdev)
 
 	schedule_work(&rtwdev->load_firmware_work);
 
+	ret = rtw89_entity_init(rtwdev);
+	if (ret)
+		return ret;
+
 	rtw89_ser_init(rtwdev);
-	rtw89_entity_init(rtwdev);
 	rtw89_sar_init(rtwdev);
 	rtw89_phy_ant_gain_init(rtwdev);
 
diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h
index 2a691daf7dab..48ef07b1d48f 100644
--- a/drivers/net/wireless/realtek/rtw89/core.h
+++ b/drivers/net/wireless/realtek/rtw89/core.h
@@ -9534,7 +9534,7 @@ void rtw89_chip_rfk_channel(struct rtw89_dev *rtwdev,
 			    struct rtw89_vif_link *rtwvif_link);
 const struct rtw89_6ghz_span *
 rtw89_get_6ghz_span(struct rtw89_dev *rtwdev, u32 center_freq);
-void rtw89_get_default_chandef(struct cfg80211_chan_def *chandef);
+int rtw89_get_default_chandef(struct rtw89_dev *rtwdev, struct cfg80211_chan_def *chandef);
 void rtw89_get_channel_params(const struct cfg80211_chan_def *chandef,
 			      struct rtw89_chan *chan);
 int rtw89_set_channel(struct rtw89_dev *rtwdev);
-- 
2.53.0


  parent reply	other threads:[~2026-11-12  6:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  6:05 [PATCH rtw-next 00/11] wifi: rtw89: correct no 2GHz band condition, update RTL8922D settings Ping-Ke Shih
2026-11-12  6:05 ` [PATCH rtw-next 01/11] wifi: rtw89: coex: add a notify entry for dynamic MLO RF-path switch Ping-Ke Shih
2026-11-12  6:05 ` [PATCH rtw-next 02/11] wifi: rtw89: pci: reclaim TXBD before fully draining Ping-Ke Shih
2026-11-12  6:05 ` [PATCH rtw-next 03/11] wifi: rtw89: 8922d: use efuse bias for CCK RX gain Ping-Ke Shih
2026-11-12  6:05 ` [PATCH rtw-next 04/11] wifi: rtw89: 8922d: set CFR clip threshold while setting channel Ping-Ke Shih
2026-11-12  6:05 ` [PATCH rtw-next 05/11] wifi: rtw89: 8922d: correct thermal trim range to -16~+16 programmed in efuse Ping-Ke Shih
2026-11-12  6:05 ` [PATCH rtw-next 06/11] wifi: rtw89: introduce bitmap of supported bands to deal with quirks Ping-Ke Shih
2026-11-12  6:05 ` Ping-Ke Shih [this message]
2026-11-12  6:05 ` [PATCH rtw-next 08/11] wifi: rtw89: fix band assignment in rtw89_core_update_rx_freq_from_ie() Ping-Ke Shih
2026-11-12  6:05 ` [PATCH rtw-next 09/11] wifi: rtw89: Update sequence for MLO link switch Ping-Ke Shih
2026-11-12  6:05 ` [PATCH rtw-next 10/11] wifi: rtw89: 8922d: enable dynamic antenna gain Ping-Ke Shih
2026-11-12  6:06 ` [PATCH rtw-next 11/11] wifi: rtw89: phy: fix antenna gain unit in debug output Ping-Ke Shih

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261112060600.71784-8-pkshih@realtek.com \
    --to=pkshih@realtek.com \
    --cc=damon.chen@realtek.com \
    --cc=kevin_yang@realtek.com \
    --cc=ku920601@realtek.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=phhuang@realtek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox