linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ping-Ke Shih <pkshih@realtek.com>
To: <kvalo@kernel.org>
Cc: <kevin_yang@realtek.com>, <linux-wireless@vger.kernel.org>
Subject: [PATCH v3 10/13] wifi: rtw89: introduce entity mode and its recalculated prototype
Date: Tue, 9 Aug 2022 18:49:49 +0800	[thread overview]
Message-ID: <20220809104952.61355-11-pkshih@realtek.com> (raw)
In-Reply-To: <20220809104952.61355-1-pkshih@realtek.com>

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

After supporting more than one channel, we need entity mode to decide
how to set current channel(s) on the sub-entities. This decision may
happen on set_channel() and rtw89_core_set_chip_txpwr().

For now, we support single one channel and use only first HW entry,
i.e. RTW89_SUB_ENTITY_0, RTW89_MAC_0, RTW89_PHY_0. Without something
unexpected, the entity mode should always be RTW89_ENT_MODE_SCC after
recalcated, where SCC means single channel concurrency. So, an assert
is added in set_channel() and rtw89_core_set_chip_txpwr().

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 | 25 ++++++++++++
 drivers/net/wireless/realtek/rtw89/chan.h | 17 +++++++++
 drivers/net/wireless/realtek/rtw89/core.c | 46 ++++++++++++++++-------
 drivers/net/wireless/realtek/rtw89/core.h |  5 +++
 4 files changed, 79 insertions(+), 14 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw89/chan.c b/drivers/net/wireless/realtek/rtw89/chan.c
index e0f1c89bbfa6b..02d31f751d3e7 100644
--- a/drivers/net/wireless/realtek/rtw89/chan.c
+++ b/drivers/net/wireless/realtek/rtw89/chan.c
@@ -3,6 +3,7 @@
  */
 
 #include "chan.h"
+#include "debug.h"
 
 static enum rtw89_subband rtw89_get_subband_type(enum rtw89_band band,
 						 u8 center_chan)
@@ -154,3 +155,27 @@ void rtw89_entity_init(struct rtw89_dev *rtwdev)
 	bitmap_zero(hal->entity_map, NUM_OF_RTW89_SUB_ENTITY);
 	rtw89_config_default_chandef(rtwdev);
 }
+
+enum rtw89_entity_mode rtw89_entity_recalc(struct rtw89_dev *rtwdev)
+{
+	struct rtw89_hal *hal = &rtwdev->hal;
+	enum rtw89_entity_mode mode;
+	u8 weight;
+
+	weight = bitmap_weight(hal->entity_map, NUM_OF_RTW89_SUB_ENTITY);
+	switch (weight) {
+	default:
+		rtw89_warn(rtwdev, "unknown ent chan weight: %d\n", weight);
+		bitmap_zero(hal->entity_map, NUM_OF_RTW89_SUB_ENTITY);
+		fallthrough;
+	case 0:
+		rtw89_config_default_chandef(rtwdev);
+		fallthrough;
+	case 1:
+		mode = RTW89_ENTITY_MODE_SCC;
+		break;
+	}
+
+	rtw89_set_entity_mode(rtwdev, mode);
+	return mode;
+}
diff --git a/drivers/net/wireless/realtek/rtw89/chan.h b/drivers/net/wireless/realtek/rtw89/chan.h
index 9c714f00c3c13..6b2b5cc0d798b 100644
--- a/drivers/net/wireless/realtek/rtw89/chan.h
+++ b/drivers/net/wireless/realtek/rtw89/chan.h
@@ -21,6 +21,22 @@ static inline void rtw89_set_entity_state(struct rtw89_dev *rtwdev, bool active)
 	WRITE_ONCE(hal->entity_active, active);
 }
 
+static inline
+enum rtw89_entity_mode rtw89_get_entity_mode(struct rtw89_dev *rtwdev)
+{
+	struct rtw89_hal *hal = &rtwdev->hal;
+
+	return READ_ONCE(hal->entity_mode);
+}
+
+static inline void rtw89_set_entity_mode(struct rtw89_dev *rtwdev,
+					 enum rtw89_entity_mode mode)
+{
+	struct rtw89_hal *hal = &rtwdev->hal;
+
+	WRITE_ONCE(hal->entity_mode, mode);
+}
+
 void rtw89_chan_create(struct rtw89_chan *chan, u8 center_chan, u8 primary_chan,
 		       enum rtw89_band band, enum rtw89_bandwidth bandwidth);
 bool rtw89_assign_entity_chan(struct rtw89_dev *rtwdev,
@@ -30,5 +46,6 @@ void rtw89_config_entity_chandef(struct rtw89_dev *rtwdev,
 				 enum rtw89_sub_entity_idx idx,
 				 const struct cfg80211_chan_def *chandef);
 void rtw89_entity_init(struct rtw89_dev *rtwdev);
+enum rtw89_entity_mode rtw89_entity_recalc(struct rtw89_dev *rtwdev);
 
 #endif
diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c
index 04ba705a14a7b..dea4280039e6a 100644
--- a/drivers/net/wireless/realtek/rtw89/core.c
+++ b/drivers/net/wireless/realtek/rtw89/core.c
@@ -295,51 +295,69 @@ void rtw89_core_set_chip_txpwr(struct rtw89_dev *rtwdev)
 {
 	const struct rtw89_chip_info *chip = rtwdev->chip;
 	const struct rtw89_chan *chan;
+	enum rtw89_sub_entity_idx sub_entity_idx;
+	enum rtw89_phy_idx phy_idx;
+	enum rtw89_entity_mode mode;
 	bool entity_active;
 
 	entity_active = rtw89_get_entity_state(rtwdev);
 	if (!entity_active)
 		return;
 
-	chan = rtw89_chan_get(rtwdev, RTW89_SUB_ENTITY_0);
+	mode = rtw89_get_entity_mode(rtwdev);
+	if (WARN(mode != RTW89_ENTITY_MODE_SCC, "Invalid ent mode: %d\n", mode))
+		return;
+
+	sub_entity_idx = RTW89_SUB_ENTITY_0;
+	phy_idx = RTW89_PHY_0;
+	chan = rtw89_chan_get(rtwdev, sub_entity_idx);
 	if (chip->ops->set_txpwr)
-		chip->ops->set_txpwr(rtwdev, chan, RTW89_PHY_0);
+		chip->ops->set_txpwr(rtwdev, chan, phy_idx);
 }
 
 void rtw89_set_channel(struct rtw89_dev *rtwdev)
 {
-	const struct cfg80211_chan_def *chandef =
-		rtw89_chandef_get(rtwdev, RTW89_SUB_ENTITY_0);
 	const struct rtw89_chip_info *chip = rtwdev->chip;
+	const struct cfg80211_chan_def *chandef;
+	enum rtw89_sub_entity_idx sub_entity_idx;
+	enum rtw89_mac_idx mac_idx;
+	enum rtw89_phy_idx phy_idx;
 	struct rtw89_chan chan;
 	struct rtw89_channel_help_params bak;
+	enum rtw89_entity_mode mode;
 	bool band_changed;
 	bool entity_active;
 
 	entity_active = rtw89_get_entity_state(rtwdev);
 
+	mode = rtw89_entity_recalc(rtwdev);
+	if (WARN(mode != RTW89_ENTITY_MODE_SCC, "Invalid ent mode: %d\n", mode))
+		return;
+
+	sub_entity_idx = RTW89_SUB_ENTITY_0;
+	mac_idx = RTW89_MAC_0;
+	phy_idx = RTW89_PHY_0;
+	chandef = rtw89_chandef_get(rtwdev, sub_entity_idx);
 	rtw89_get_channel_params(chandef, &chan);
 	if (WARN(chan.channel == 0, "Invalid channel\n"))
 		return;
 
-	band_changed = rtw89_assign_entity_chan(rtwdev, RTW89_SUB_ENTITY_0, &chan);
-
-	rtw89_set_entity_state(rtwdev, true);
+	band_changed = rtw89_assign_entity_chan(rtwdev, sub_entity_idx, &chan);
 
-	rtw89_chip_set_channel_prepare(rtwdev, &bak, &chan,
-				       RTW89_MAC_0, RTW89_PHY_0);
+	rtw89_chip_set_channel_prepare(rtwdev, &bak, &chan, mac_idx, phy_idx);
 
-	chip->ops->set_channel(rtwdev, &chan, RTW89_MAC_0, RTW89_PHY_0);
+	chip->ops->set_channel(rtwdev, &chan, mac_idx, phy_idx);
 
 	rtw89_core_set_chip_txpwr(rtwdev);
 
-	rtw89_chip_set_channel_done(rtwdev, &bak, &chan,
-				    RTW89_MAC_0, RTW89_PHY_0);
+	rtw89_chip_set_channel_done(rtwdev, &bak, &chan, mac_idx, phy_idx);
 
 	if (!entity_active || band_changed) {
-		rtw89_btc_ntfy_switch_band(rtwdev, RTW89_PHY_0, chan.band_type);
-		rtw89_chip_rfk_band_changed(rtwdev, RTW89_PHY_0);
+		rtw89_btc_ntfy_switch_band(rtwdev, phy_idx, chan.band_type);
+		rtw89_chip_rfk_band_changed(rtwdev, phy_idx);
 	}
+
+	rtw89_set_entity_state(rtwdev, true);
 }
 
 static enum rtw89_core_tx_type
diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h
index 3b6660d76f797..96af628d8d46e 100644
--- a/drivers/net/wireless/realtek/rtw89/core.h
+++ b/drivers/net/wireless/realtek/rtw89/core.h
@@ -2623,6 +2623,10 @@ struct rtw89_sar_info {
 	};
 };
 
+enum rtw89_entity_mode {
+	RTW89_ENTITY_MODE_SCC,
+};
+
 struct rtw89_hal {
 	u32 rx_fltr;
 	u8 cv;
@@ -2638,6 +2642,7 @@ struct rtw89_hal {
 	struct cfg80211_chan_def chandef[NUM_OF_RTW89_SUB_ENTITY];
 
 	bool entity_active;
+	enum rtw89_entity_mode entity_mode;
 
 	struct rtw89_chan chan[NUM_OF_RTW89_SUB_ENTITY];
 	struct rtw89_chan_rcd chan_rcd[NUM_OF_RTW89_SUB_ENTITY];
-- 
2.25.1


  parent reply	other threads:[~2022-08-09 10:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-09 10:49 [PATCH v3 00/13] rtw89: support channel context Ping-Ke Shih
2022-08-09 10:49 ` [PATCH v3 01/13] wifi: rtw89: rewrite decision on channel by entity state Ping-Ke Shih
2022-09-02  8:30   ` Kalle Valo
2022-08-09 10:49 ` [PATCH v3 02/13] wifi: rtw89: introduce rtw89_chan for channel stuffs Ping-Ke Shih
2022-08-09 10:49 ` [PATCH v3 03/13] wifi: rtw89: re-arrange channel related stuffs under HAL Ping-Ke Shih
2022-08-09 10:49 ` [PATCH v3 04/13] wifi: rtw89: create rtw89_chan centrally to avoid breakage Ping-Ke Shih
2022-08-09 10:49 ` [PATCH v3 05/13] wifi: rtw89: txpwr: concentrate channel related control to top Ping-Ke Shih
2022-08-09 10:49 ` [PATCH v3 06/13] wifi: rtw89: rfk: concentrate parameter control while set_channel() Ping-Ke Shih
2022-08-09 10:49 ` [PATCH v3 07/13] wifi: rtw89: concentrate parameter control for setting channel callback Ping-Ke Shih
2022-08-09 10:49 ` [PATCH v3 08/13] wifi: rtw89: concentrate chandef setting to stack callback Ping-Ke Shih
2022-08-09 10:49 ` [PATCH v3 09/13] wifi: rtw89: initialize entity and configure default chandef Ping-Ke Shih
2022-08-09 10:49 ` Ping-Ke Shih [this message]
2022-08-09 10:49 ` [PATCH v3 11/13] wifi: rtw89: add skeleton of mac80211 chanctx ops support Ping-Ke Shih
2022-08-09 10:49 ` [PATCH v3 12/13] wifi: rtw89: declare support for mac80211 chanctx ops by chip Ping-Ke Shih
2022-08-09 10:49 ` [PATCH v3 13/13] wifi: rtw89: early recognize FW feature to decide if chanctx Ping-Ke Shih
2022-09-02  8:23   ` Kalle Valo

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=20220809104952.61355-11-pkshih@realtek.com \
    --to=pkshih@realtek.com \
    --cc=kevin_yang@realtek.com \
    --cc=kvalo@kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).