mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Chih-Kang Chang <gary.chang@realtek.com>,
	Ping-Ke Shih <pkshih@realtek.com>,
	Sasha Levin <sashal@kernel.org>,
	kvalo@kernel.org, linux-wireless@vger.kernel.org
Subject: [PATCH AUTOSEL 6.6 01/19] wifi: rtw89: add crystal_cap check to avoid setting as overflow value
Date: Sun, 26 Jan 2025 10:02:56 -0500	[thread overview]
Message-ID: <20250126150315.956795-1-sashal@kernel.org> (raw)

From: Chih-Kang Chang <gary.chang@realtek.com>

[ Upstream commit 7b98caea39676561f22db58752551161bb36462b ]

In the original flow, the crystal_cap might be calculated as a negative
value and set as an overflow value. Therefore, we added a check to limit
the calculated crystal_cap value. Additionally, we shrank the crystal_cap
adjustment according to specific CFO.

Signed-off-by: Chih-Kang Chang <gary.chang@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Link: https://patch.msgid.link/20241128055433.11851-7-pkshih@realtek.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/wireless/realtek/rtw89/phy.c | 11 ++++++-----
 drivers/net/wireless/realtek/rtw89/phy.h |  2 +-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw89/phy.c b/drivers/net/wireless/realtek/rtw89/phy.c
index fac83b718a30c..457c1dd31bf9d 100644
--- a/drivers/net/wireless/realtek/rtw89/phy.c
+++ b/drivers/net/wireless/realtek/rtw89/phy.c
@@ -2438,7 +2438,6 @@ static void rtw89_phy_cfo_set_crystal_cap(struct rtw89_dev *rtwdev,
 
 	if (!force && cfo->crystal_cap == crystal_cap)
 		return;
-	crystal_cap = clamp_t(u8, crystal_cap, 0, 127);
 	if (chip->chip_id == RTL8852A || chip->chip_id == RTL8851B) {
 		rtw89_phy_cfo_set_xcap_reg(rtwdev, true, crystal_cap);
 		rtw89_phy_cfo_set_xcap_reg(rtwdev, false, crystal_cap);
@@ -2552,7 +2551,7 @@ static void rtw89_phy_cfo_crystal_cap_adjust(struct rtw89_dev *rtwdev,
 					     s32 curr_cfo)
 {
 	struct rtw89_cfo_tracking_info *cfo = &rtwdev->cfo_tracking;
-	s8 crystal_cap = cfo->crystal_cap;
+	int crystal_cap = cfo->crystal_cap;
 	s32 cfo_abs = abs(curr_cfo);
 	int sign;
 
@@ -2569,15 +2568,17 @@ static void rtw89_phy_cfo_crystal_cap_adjust(struct rtw89_dev *rtwdev,
 	}
 	sign = curr_cfo > 0 ? 1 : -1;
 	if (cfo_abs > CFO_TRK_STOP_TH_4)
-		crystal_cap += 7 * sign;
+		crystal_cap += 3 * sign;
 	else if (cfo_abs > CFO_TRK_STOP_TH_3)
-		crystal_cap += 5 * sign;
-	else if (cfo_abs > CFO_TRK_STOP_TH_2)
 		crystal_cap += 3 * sign;
+	else if (cfo_abs > CFO_TRK_STOP_TH_2)
+		crystal_cap += 1 * sign;
 	else if (cfo_abs > CFO_TRK_STOP_TH_1)
 		crystal_cap += 1 * sign;
 	else
 		return;
+
+	crystal_cap = clamp(crystal_cap, 0, 127);
 	rtw89_phy_cfo_set_crystal_cap(rtwdev, (u8)crystal_cap, false);
 	rtw89_debug(rtwdev, RTW89_DBG_CFO,
 		    "X_cap{Curr,Default}={0x%x,0x%x}\n",
diff --git a/drivers/net/wireless/realtek/rtw89/phy.h b/drivers/net/wireless/realtek/rtw89/phy.h
index d6dc0cbbae43b..15ed23fa4218f 100644
--- a/drivers/net/wireless/realtek/rtw89/phy.h
+++ b/drivers/net/wireless/realtek/rtw89/phy.h
@@ -51,7 +51,7 @@
 #define CFO_TRK_STOP_TH_4 (30 << 2)
 #define CFO_TRK_STOP_TH_3 (20 << 2)
 #define CFO_TRK_STOP_TH_2 (10 << 2)
-#define CFO_TRK_STOP_TH_1 (00 << 2)
+#define CFO_TRK_STOP_TH_1 (03 << 2)
 #define CFO_TRK_STOP_TH (2 << 2)
 #define CFO_SW_COMP_FINE_TUNE (2 << 2)
 #define CFO_PERIOD_CNT 15
-- 
2.39.5


             reply	other threads:[~2025-01-26 15:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-26 15:02 Sasha Levin [this message]
2025-01-26 15:02 ` [PATCH AUTOSEL 6.6 02/19] tun: fix group permission check Sasha Levin
2025-01-26 15:02 ` [PATCH AUTOSEL 6.6 03/19] mmc: core: Respect quirk_max_rate for non-UHS SDIO card Sasha Levin
2025-01-26 15:02 ` [PATCH AUTOSEL 6.6 04/19] Revert "HID: multitouch: Add support for lenovo Y9000P Touchpad" Sasha Levin
2025-01-26 15:03 ` [PATCH AUTOSEL 6.6 05/19] wifi: brcmsmac: add gain range check to wlc_phy_iqcal_gainparams_nphy() Sasha Levin
2025-01-26 15:03 ` [PATCH AUTOSEL 6.6 06/19] tomoyo: don't emit warning in tomoyo_write_control() Sasha Levin
2025-01-26 15:03 ` [PATCH AUTOSEL 6.6 07/19] mfd: lpc_ich: Add another Gemini Lake ISA bridge PCI device-id Sasha Levin
2025-01-26 15:03 ` [PATCH AUTOSEL 6.6 08/19] clk: qcom: Make GCC_8150 depend on QCOM_GDSC Sasha Levin
2025-01-26 15:03 ` [PATCH AUTOSEL 6.6 09/19] HID: Wacom: Add PCI Wacom device support Sasha Levin
2025-01-26 15:03 ` [PATCH AUTOSEL 6.6 10/19] net/mlx5: use do_aux_work for PHC overflow checks Sasha Levin
2025-01-26 15:03 ` [PATCH AUTOSEL 6.6 11/19] wifi: brcmfmac: Check the return value of of_property_read_string_index() Sasha Levin
2025-01-26 15:03 ` [PATCH AUTOSEL 6.6 12/19] wifi: iwlwifi: avoid memory leak Sasha Levin
2025-01-26 15:03 ` [PATCH AUTOSEL 6.6 13/19] i2c: Force ELAN06FA touchpad I2C bus freq to 100KHz Sasha Levin
2025-01-26 15:03 ` [PATCH AUTOSEL 6.6 14/19] APEI: GHES: Have GHES honor the panic= setting Sasha Levin
2025-01-26 15:03 ` [PATCH AUTOSEL 6.6 15/19] Bluetooth: MGMT: Fix slab-use-after-free Read in mgmt_remove_adv_monitor_sync Sasha Levin
2025-01-26 15:03 ` [PATCH AUTOSEL 6.6 16/19] net: wwan: iosm: Fix hibernation by re-binding the driver around it Sasha Levin
2025-01-26 15:03 ` [PATCH AUTOSEL 6.6 17/19] mmc: sdhci-msm: Correctly set the load for the regulator Sasha Levin
2025-01-26 15:03 ` [PATCH AUTOSEL 6.6 18/19] tipc: re-order conditions in tipc_crypto_key_rcv() Sasha Levin
2025-01-26 15:03 ` [PATCH AUTOSEL 6.6 19/19] selftests/net/ipsec: Fix Null pointer dereference in rtattr_pack() Sasha Levin

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=20250126150315.956795-1-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=gary.chang@realtek.com \
    --cc=kvalo@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=pkshih@realtek.com \
    --cc=stable@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

all inboxes | Powered by JetHome®